Merge pull request 'Implement minor fixes' (#9) from minor-fixes into master
Reviewed-on: #9
This commit is contained in:
commit
a061ffd350
@ -12,7 +12,7 @@ docker:
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY +build/budgeteer .
|
COPY +build/budgeteer .
|
||||||
ENTRYPOINT ["/app/budgeteer"]
|
ENTRYPOINT ["/app/budgeteer"]
|
||||||
SAVE IMAGE budgeteer:latest
|
SAVE IMAGE hub.javil.eu/budgeteer:latest
|
||||||
|
|
||||||
run:
|
run:
|
||||||
LOCALLY
|
LOCALLY
|
||||||
|
@ -2,9 +2,7 @@ version: '3.7'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
image: budgeteer:dev
|
image: hub.javil.eu/budgeteer:dev
|
||||||
build:
|
|
||||||
context: ./docker/
|
|
||||||
container_name: budgeteer
|
container_name: budgeteer
|
||||||
stdin_open: true # docker run -i
|
stdin_open: true # docker run -i
|
||||||
tty: true # docker run -t
|
tty: true # docker run -t
|
||||||
|
@ -2,7 +2,7 @@ version: '3.7'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
image: budgeteer:latest
|
image: hub.javil.eu/budgeteer:latest
|
||||||
container_name: budgeteer
|
container_name: budgeteer
|
||||||
ports:
|
ports:
|
||||||
- 1323:1323
|
- 1323:1323
|
||||||
|
41
http/http.go
41
http/http.go
@ -1,8 +1,11 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.javil.eu/jacob1123/budgeteer"
|
"git.javil.eu/jacob1123/budgeteer"
|
||||||
@ -18,6 +21,7 @@ type Handler struct {
|
|||||||
Service *postgres.Database
|
Service *postgres.Database
|
||||||
TokenVerifier budgeteer.TokenVerifier
|
TokenVerifier budgeteer.TokenVerifier
|
||||||
CredentialsVerifier *bcrypt.Verifier
|
CredentialsVerifier *bcrypt.Verifier
|
||||||
|
StaticFS http.FileSystem
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -37,14 +41,10 @@ func (h *Handler) LoadRoutes(router *gin.Engine) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic("couldn't open static files")
|
panic("couldn't open static files")
|
||||||
}
|
}
|
||||||
staticFS := http.FS(static)
|
h.StaticFS = http.FS(static)
|
||||||
|
|
||||||
router.Use(enableCachingForStaticFiles())
|
router.Use(enableCachingForStaticFiles())
|
||||||
router.NoRoute(
|
router.NoRoute(h.ServeStatic)
|
||||||
func(c *gin.Context) {
|
|
||||||
c.FileFromFS(c.Request.URL.Path, staticFS)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
withLogin := router.Group("")
|
withLogin := router.Group("")
|
||||||
withLogin.Use(h.verifyLoginWithRedirect)
|
withLogin.Use(h.verifyLoginWithRedirect)
|
||||||
@ -81,6 +81,35 @@ func (h *Handler) LoadRoutes(router *gin.Engine) {
|
|||||||
transaction.POST("/new", h.newTransaction)
|
transaction.POST("/new", h.newTransaction)
|
||||||
transaction.POST("/:transactionid", h.newTransaction)
|
transaction.POST("/:transactionid", h.newTransaction)
|
||||||
}
|
}
|
||||||
|
func (h *Handler) ServeStatic(c *gin.Context) {
|
||||||
|
h.ServeStaticFile(c, c.Request.URL.Path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) ServeStaticFile(c *gin.Context, fullPath string) {
|
||||||
|
file, err := h.StaticFS.Open(fullPath)
|
||||||
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
|
h.ServeStaticFile(c, path.Join("/", "/index.html"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stat, err := file.Stat()
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if stat.IsDir() {
|
||||||
|
h.ServeStaticFile(c, path.Join(fullPath, "index.html"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.ServeContent(c.Writer, c.Request, stat.Name(), stat.ModTime(), file.(io.ReadSeeker))
|
||||||
|
}
|
||||||
|
|
||||||
func enableCachingForStaticFiles() gin.HandlerFunc {
|
func enableCachingForStaticFiles() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
@ -21,7 +21,7 @@ export interface Budget {
|
|||||||
export const useSessionStore = defineStore('session', {
|
export const useSessionStore = defineStore('session', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
Session: useStorage<Session>('session', null, undefined, { serializer: StorageSerializers.object }),
|
Session: useStorage<Session>('session', null, undefined, { serializer: StorageSerializers.object }),
|
||||||
Budgets: useStorage<Map<string, Budget>>('budgets', new Map<string, Budget>()),
|
Budgets: useStorage<Map<string, Budget>>('budgets', new Map<string, Budget>(), undefined, { serializer: StorageSerializers.map }),
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
BudgetsList: (state) => [ ...state.Budgets.values() ],
|
BudgetsList: (state) => [ ...state.Budgets.values() ],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user