From db11db128187d0eb75b822333db543b94caec833 Mon Sep 17 00:00:00 2001 From: sundowndev Date: Thu, 16 Apr 2020 22:59:31 +0100 Subject: [PATCH] refactor(client): static path --- api/server.go | 26 ++++++++++++++------------ client/vue.config.js | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/api/server.go b/api/server.go index dab6bd410..58745e991 100644 --- a/api/server.go +++ b/api/server.go @@ -10,7 +10,7 @@ import ( const ( clientDistPath = "/client/dist/" - staticPath = "/static/" + staticPath = "/" ) func detectContentType(path string, data []byte) string { @@ -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() }) } diff --git a/client/vue.config.js b/client/vue.config.js index 8e7a9aecf..0de1dc6ff 100644 --- a/client/vue.config.js +++ b/client/vue.config.js @@ -1,3 +1,3 @@ module.exports = { - publicPath: "/static", + publicPath: "/", };