Skip to content

Commit

Permalink
refactor(client): static path
Browse files Browse the repository at this point in the history
  • Loading branch information
sundowndev committed Apr 16, 2020
1 parent ae41816 commit db11db1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

const (
clientDistPath = "/client/dist/"
staticPath = "/static/"
staticPath = "/"
)

func detectContentType(path string, data []byte) string {
Expand All @@ -31,21 +31,23 @@ func detectContentType(path string, data []byte) string {

func registerClientRoute(router *gin.Engine) {
for name, file := range Assets.Files {
if !file.IsDir() {
path := strings.ReplaceAll(name, clientDistPath, staticPath)
data := file.Data

router.GET(path, func(c *gin.Context) {
c.Header("Content-Type", detectContentType(path, data))
c.Writer.WriteHeader(http.StatusOK)
c.Writer.Write(data)
c.Abort()
})
if file.IsDir() {
continue
}

path := strings.ReplaceAll(name, clientDistPath, staticPath)
data := file.Data

router.GET(path, func(c *gin.Context) {
c.Header("Content-Type", detectContentType(path, data))
c.Writer.WriteHeader(http.StatusOK)
c.Writer.Write(data)
c.Abort()
})
}

router.GET("/", func(c *gin.Context) {
c.Redirect(302, "/static/index.html")
c.Redirect(302, staticPath+"index.html")
c.Abort()
})
}
Expand Down
2 changes: 1 addition & 1 deletion client/vue.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
publicPath: "/static",
publicPath: "/",
};

0 comments on commit db11db1

Please sign in to comment.