Fix html rendering
This commit is contained in:
parent
be890e2e75
commit
1629523d84
7 changed files with 56 additions and 4 deletions
|
@ -5,8 +5,8 @@ unit_tests:
|
||||||
extends:
|
extends:
|
||||||
- .go-cache
|
- .go-cache
|
||||||
script:
|
script:
|
||||||
- ./swagger.sh install
|
- ./scripts/swagger.sh install
|
||||||
- ./swagger.sh init
|
- ./scripts/swagger.sh init
|
||||||
- go install gotest.tools/gotestsum@latest
|
- go install gotest.tools/gotestsum@latest
|
||||||
- gotestsum --junitfile report.xml --format testname -- ./... -coverprofile=profile.cov
|
- gotestsum --junitfile report.xml --format testname -- ./... -coverprofile=profile.cov
|
||||||
- go tool cover -func profile.cov
|
- go tool cover -func profile.cov
|
||||||
|
|
|
@ -115,6 +115,7 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- PUID=1000
|
- PUID=1000
|
||||||
- PGID=1000
|
- PGID=1000
|
||||||
|
- SWAGGER_HOST=https://cafe.test
|
||||||
labels:
|
labels:
|
||||||
- 'traefik.enable=true'
|
- 'traefik.enable=true'
|
||||||
- 'traefik.http.routers.backend.rule=Host(`cafe.test`) && PathPrefix(`/api`)'
|
- 'traefik.http.routers.backend.rule=Host(`cafe.test`) && PathPrefix(`/api`)'
|
||||||
|
|
|
@ -39,7 +39,7 @@ WORKDIR /app
|
||||||
COPY ./scripts/entrypoint.sh .
|
COPY ./scripts/entrypoint.sh .
|
||||||
|
|
||||||
COPY --from=logo /logo.txt .
|
COPY --from=logo /logo.txt .
|
||||||
COPY --from=nodeBuilder /app/dist/ ./templates/
|
COPY --from=nodeBuilder /app/dist/ ./web/
|
||||||
COPY --from=goBuilder /app/cafe-plaetschwiesle .
|
COPY --from=goBuilder /app/cafe-plaetschwiesle .
|
||||||
|
|
||||||
ARG VERSION
|
ARG VERSION
|
||||||
|
|
2
internal/env/env.go
vendored
2
internal/env/env.go
vendored
|
@ -15,7 +15,7 @@ type Config struct {
|
||||||
Port int `env:"PORT" envDefault:"8080" validate:"min=1024,max=49151"`
|
Port int `env:"PORT" envDefault:"8080" validate:"min=1024,max=49151"`
|
||||||
LogLevel string `env:"LOG_LEVEL" envDefault:"info" validate:"oneof=debug info warn error panic fatal"`
|
LogLevel string `env:"LOG_LEVEL" envDefault:"info" validate:"oneof=debug info warn error panic fatal"`
|
||||||
Version string `env:"VERSION" envDefault:"v0.0.0"`
|
Version string `env:"VERSION" envDefault:"v0.0.0"`
|
||||||
SwaggerHost string `env:"SWAGGER_HOST" envDefault:"https://cafe.test"`
|
SwaggerHost string `env:"SWAGGER_HOST"`
|
||||||
DB_Host string `env:"DB_HOST"`
|
DB_Host string `env:"DB_HOST"`
|
||||||
DB_User string `env:"DB_USER"`
|
DB_User string `env:"DB_USER"`
|
||||||
DB_Password string `env:"DB_PASSWORD"`
|
DB_Password string `env:"DB_PASSWORD"`
|
||||||
|
|
|
@ -4,6 +4,13 @@ import (
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func longCacheLifetime(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
|
return func(c echo.Context) error {
|
||||||
|
c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=31536000")
|
||||||
|
return next(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func authHeader(next echo.HandlerFunc) echo.HandlerFunc {
|
func authHeader(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
c.Response().Header().Set("Remote-Groups", c.Request().Header.Get("Remote-Groups"))
|
c.Response().Header().Set("Remote-Groups", c.Request().Header.Get("Remote-Groups"))
|
||||||
|
|
|
@ -29,11 +29,26 @@ func InitRouter() *echo.Echo {
|
||||||
e.Pre(middleware.RemoveTrailingSlash())
|
e.Pre(middleware.RemoveTrailingSlash())
|
||||||
|
|
||||||
e.Validator = &CustomValidator{Validator: newValidator()}
|
e.Validator = &CustomValidator{Validator: newValidator()}
|
||||||
|
e.Renderer = initTemplates()
|
||||||
|
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupRoutes(e *echo.Echo, ctrl *controller.Controller, env *env.Config) {
|
func SetupRoutes(e *echo.Echo, ctrl *controller.Controller, env *env.Config) {
|
||||||
|
favicon := e.Group("/favicon", longCacheLifetime)
|
||||||
|
favicon.Static("/", "web/favicon")
|
||||||
|
fonts := e.Group("/fonts", longCacheLifetime)
|
||||||
|
fonts.Static("/", "web/fonts")
|
||||||
|
img := e.Group("/img", longCacheLifetime)
|
||||||
|
img.Static("/", "web/img")
|
||||||
|
|
||||||
|
e.Static("/css", "web/css")
|
||||||
|
e.Static("/js", "web/js")
|
||||||
|
|
||||||
|
e.GET("/", func(c echo.Context) error {
|
||||||
|
return c.Render(http.StatusOK, "index.html", nil)
|
||||||
|
})
|
||||||
|
|
||||||
api := e.Group("/api")
|
api := e.Group("/api")
|
||||||
{
|
{
|
||||||
tableGroup := api.Group("/tables")
|
tableGroup := api.Group("/tables")
|
||||||
|
@ -79,6 +94,13 @@ func SetupRoutes(e *echo.Echo, ctrl *controller.Controller, env *env.Config) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.GET("/robots.txt", func(ctx echo.Context) error {
|
||||||
|
return ctx.String(http.StatusOK, "User-agent: *\nDisallow: /")
|
||||||
|
})
|
||||||
|
e.RouteNotFound("*", func(ctx echo.Context) error {
|
||||||
|
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
|
||||||
|
})
|
||||||
|
|
||||||
if env.SwaggerHost != "" {
|
if env.SwaggerHost != "" {
|
||||||
docs.SwaggerInfo.Title = "Café Plätschwiesle"
|
docs.SwaggerInfo.Title = "Café Plätschwiesle"
|
||||||
docs.SwaggerInfo.Description = "This is the backend of Café Plätschwiesle"
|
docs.SwaggerInfo.Description = "This is the backend of Café Plätschwiesle"
|
||||||
|
|
22
internal/router/templates.go
Normal file
22
internal/router/templates.go
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Template struct {
|
||||||
|
templates *template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
||||||
|
return t.templates.ExecuteTemplate(w, name, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initTemplates() *Template {
|
||||||
|
return &Template{
|
||||||
|
templates: template.Must(template.ParseGlob("web/*.html")),
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue