grim/devweb

bacc8aeab2fe
Parents 0bbebc2e7606
Children 454462e98cfc
Don't embed the frontend instead expose it on /app
--- a/.hgignore Thu Jul 16 19:03:10 2020 -0500
+++ b/.hgignore Fri Nov 13 23:04:28 2020 -0600
@@ -4,4 +4,3 @@
db/scheme/embedded.go
data
frontend/dist/*
-frontend/embedded.go
--- a/frontend/frontend.go Thu Jul 16 19:03:10 2020 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-//go:generate esc -o embedded.go -pkg frontend -include .+ -prefix dist dist/
-package frontend
-
-import (
- "net/http"
- "path/filepath"
-
- "github.com/gin-gonic/contrib/static"
- "github.com/gin-gonic/gin"
-)
-
-type embeddedFS struct {
- http.FileSystem
-}
-
-func (e *embeddedFS) Exists(prefix, path string) bool {
- full := filepath.Join(prefix, path)
- if _, found := _escData[full]; !found {
- return false
- }
-
- return true
-}
-
-func Routes(router *gin.Engine) {
- router.Use(static.Serve("/", &embeddedFS{FileSystem: Dir(false, "/")}))
-}
--- a/frontend/vue.config.js Thu Jul 16 19:03:10 2020 -0500
+++ b/frontend/vue.config.js Fri Nov 13 23:04:28 2020 -0600
@@ -1,4 +1,5 @@
module.exports = {
+ publicPath: "/app/",
pluginOptions: {
i18n: {
locale: 'en',
--- a/server/cmd.go Thu Jul 16 19:03:10 2020 -0500
+++ b/server/cmd.go Fri Nov 13 23:04:28 2020 -0600
@@ -13,8 +13,9 @@
type Cmd struct {
db.Options
- ListenAddr string `kong:"flag,name='listen-addr',help='The address to listen on.',default=':1234'"`
- StoragePath string `kong:"flag,name='storage-path',help='The path to store files in.',default='data'"`
+ ListenAddr string `kong:"flag,name='listen-addr',help='The address to listen on.',default=':1234'"`
+ StoragePath string `kong:"flag,name='storage-path',help='The path to store files in.',default='data'"`
+ FrontendPath string `kong:"flag,name='frontend-path',help='The path to the frontend files.',default='frontend'"`
}
func (c *Cmd) Run() error {
@@ -38,7 +39,7 @@
defer server.Close()
go func() {
- if err := server.Listen(); err != nil {
+ if err := server.Listen(c.FrontendPath); err != nil {
errChan <- err
}
}()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/server/handlers.go Fri Nov 13 23:04:28 2020 -0600
@@ -0,0 +1,9 @@
+package server
+
+import (
+ "github.com/gin-gonic/gin"
+)
+
+func redirectToApp(c *gin.Context) {
+ c.Redirect(307, "/app")
+}
--- a/server/server.go Thu Jul 16 19:03:10 2020 -0500
+++ b/server/server.go Fri Nov 13 23:04:28 2020 -0600
@@ -7,7 +7,6 @@
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
- "keep.imfreedom.org/grim/devweb/frontend"
"keep.imfreedom.org/grim/devweb/storage"
"keep.imfreedom.org/grim/devweb/v1"
)
@@ -31,13 +30,16 @@
}
}
-func (s *Server) Listen() error {
+func (s *Server) Listen(frontendPath string) error {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
+ // redirect / to /app
+ router.GET("/", redirectToApp)
+
// add the frontend routes
- frontend.Routes(router)
+ router.Static("/app/", frontendPath)
// add our storage routes
s.storage.Routes(&router.RouterGroup)