So I'm using a go server to serve up a single page web application.
This works for serving all the assets on the root route. All the CSS and HTML are served up correctly.
fs := http.FileServer(http.Dir("build"))
http.Handle("/", fs)
So when the URL is http://myserverurl/index.html
or http://myserverurl/styles.css
, it serves the corresponding file.
But for a URL like http://myserverurl/myCustompage
, it throws 404
if myCustompage
is not a file in the build folder.
How do I make all routes for which a file does not exist serve index.html
?
It is a single page web application and it will render the appropriate screen once the html and js are served. But it needs index.html
to be served on routes for which there is no file.
How can this be done?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…