bisakhmondal commented on a change in pull request #1788:
URL: https://github.com/apache/apisix-dashboard/pull/1788#discussion_r634526940
##########
File path: api/internal/route.go
##########
@@ -91,3 +94,55 @@ func SetUpRouter() *gin.Engine {
return r
}
+
+type spaFileSystem struct {
+ http.FileSystem
+}
+
+func (fs *spaFileSystem) Open(name string) (http.File, error) {
+ f, err := fs.FileSystem.Open(name)
+ //Default failsafe page
+ if err != nil {
+ return fs.FileSystem.Open("index.html")
+ }
+ return f, err
+}
+
+var HTMLBlackListRoutes = []string{
+ "/apisix",
+ "/ping",
+}
+
+func serve(urlPrefix string, fss fs.FS) gin.HandlerFunc {
+ fileserver := http.FileServer(&spaFileSystem{http.FS(fss)})
+ if urlPrefix != "" {
+ fileserver = http.StripPrefix(urlPrefix, fileserver)
+ }
+ return func(c *gin.Context) {
+
+ if c.Request.Method == "GET" &&
+ (exists(urlPrefix, c.Request.URL.Path, &fss) ||
!isBlacklisted(c.Request.URL.Path)) {
Review comment:
Actually its all because Single Page Application strategy followed by
React.js. As there is a single `index.html` and each time for a different route
the sameDOM gets updated.
Actually for web server the `exists` methods makes sense, as the serving is
acted as a middleware, obviously we wouldn't wish to shove HTML content for
each request, some condition checking must be there. `exists` check is the
required resource file (got through the request path) is present in the HTML
directory, if yes, send the file and terminate the request from further
propagation, else pass the request to next middleware.
This was okay until I checked with direct route pasted on the browser for
eg, (localhost:9000/route/list), as it was not propagated from index.html the
`exists` didn't work. But rest of the cases from login to page visits, logout
everything was fine.
So I came up with `isBlacklisted`, if the route prefix is not HTML
blacklisted for example `/admin` or `/ping` and the request type is `GET` serve
the static HTML.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]