serve static files and docker

This commit is contained in:
Niklas Kapelle 2023-11-07 00:21:12 +01:00
parent bb6c61b08e
commit 37ea5eb926
Signed by: niklas
GPG Key ID: 4EB651B36D841D16
2 changed files with 21 additions and 0 deletions

View File

@ -1,3 +1,11 @@
FROM --platform=$BUILDPLATFORM node:20-alpine as webbuild
COPY . /build
WORKDIR /build/frontend
RUN npm ci && npm run build
FROM --platform=$BUILDPLATFORM golang:1.21-alpine as build FROM --platform=$BUILDPLATFORM golang:1.21-alpine as build
ADD . /app ADD . /app
@ -15,6 +23,7 @@ FROM --platform=$TARGETPLATFORM alpine:latest
WORKDIR /data WORKDIR /data
RUN apk add --no-cache tzdata ca-certificates RUN apk add --no-cache tzdata ca-certificates
COPY --from=build /app/build/morningalarm /app/morningalarm COPY --from=build /app/build/morningalarm /app/morningalarm
COPY --from=webbuild /build/frontend/dist /app/public
EXPOSE 3000 EXPOSE 3000

View File

@ -2,6 +2,8 @@ package morningalarm
import ( import (
"net/http" "net/http"
"os"
"path/filepath"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -17,6 +19,16 @@ type AlarmPatch struct {
} }
func (ma *MorningAlarm) setupWebserver() { func (ma *MorningAlarm) setupWebserver() {
// TODO: This is stupid
execPath, err := os.Executable()
if err != nil {
panic("Shit")
}
// Serve static files
ma.ro.NoRoute(gin.WrapH(http.FileServer(http.Dir(filepath.Join(filepath.Dir(execPath), "public")))))
// Create a new alarm // Create a new alarm
ma.ro.POST("/api/alarm", func(c *gin.Context) { ma.ro.POST("/api/alarm", func(c *gin.Context) {
var body alarm var body alarm