From 37ea5eb926ef9357ac2bebfc1b86a6a7171e6946 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Tue, 7 Nov 2023 00:21:12 +0100 Subject: [PATCH] serve static files and docker --- Dockerfile | 9 +++++++++ internal/webserver.go | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Dockerfile b/Dockerfile index 79e82aa..8d0728d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 ADD . /app @@ -15,6 +23,7 @@ FROM --platform=$TARGETPLATFORM alpine:latest WORKDIR /data RUN apk add --no-cache tzdata ca-certificates COPY --from=build /app/build/morningalarm /app/morningalarm +COPY --from=webbuild /build/frontend/dist /app/public EXPOSE 3000 diff --git a/internal/webserver.go b/internal/webserver.go index 00d8195..2c3d3bb 100644 --- a/internal/webserver.go +++ b/internal/webserver.go @@ -2,6 +2,8 @@ package morningalarm import ( "net/http" + "os" + "path/filepath" "time" "github.com/gin-gonic/gin" @@ -17,6 +19,16 @@ type AlarmPatch struct { } 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 ma.ro.POST("/api/alarm", func(c *gin.Context) { var body alarm