Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback file for single page applications #82

Closed
wants to merge 6 commits into from

Conversation

cwen0
Copy link

@cwen0 cwen0 commented Jun 27, 2020

In the case of SPA apps (Angular, React, Vue, ...) when you hit the refresh button and the route doesn't match the pattern you can specify a fallback file that is served if no other is found.

eg: in most cases, we can specify index.html as the fallback file.

Signed-off-by: cwen0 <cwenyin0@gmail.com>
Signed-off-by: cwen0 <cwenyin0@gmail.com>
Signed-off-by: cwen0 <cwenyin0@gmail.com>
Signed-off-by: cwen0 <cwenyin0@gmail.com>
@dmitshur
Copy link
Member

Hi there, thanks for the PR.

This functionality makes sense, but it can and should be out of scope for vfsgen. The goal of vfsgen is to convert a dynamic http.FileSystem into a statically-encoded one. Everything else that is higher level should be done by other libraries or application.

The functionality to serve a fallback file can be implemented quite easily:

f, err := fs.Open(path)
if os.IsNotExist(err) {
    f, err = fs.Open("/index.html")
}
if err != nil {
    // handle error
}
// serve file f (e.g., with http.ServeContent)

@cwen0
Copy link
Author

cwen0 commented Jun 28, 2020

@dmitshur Thanks for your advice. I will close this pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants