From 9ecad37f80add461bf19bce73f41b5c43f9dc9b2 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Tue, 10 Nov 2020 20:02:48 +0100 Subject: [PATCH 1/2] Dockerfile: build smaller dist --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7da3659..649fd72 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,21 @@ FROM node:14.14.0-alpine3.10 AS builder WORKDIR / COPY package.json package-lock.json ./ -RUN npm install && mkdir frontend +RUN npm install && npm install -g @angular/cli && mkdir frontend RUN mv node_modules ./frontend WORKDIR /frontend COPY . . -RUN npm run ng build --prod --crossOrigin=anonymous +RUN ng build --prod --crossOrigin=anonymous FROM golang:1.13.4-alpine as builder2 RUN apk add git WORKDIR / -COPY --from=builder /frontend/dist /dist +COPY --from=builder /frontend/dist /dist RUN go get github.com/rakyll/statik RUN statik --src=/dist/flotte-frontend COPY *.go *.sum *.mod / -COPY vendor ./vendor +COPY vendor /vendor RUN CGO_ENABLED=0 GOOS=linux go build --mod=vendor -o frontend_server FROM scratch From 6091903ed7f6be1e4afa53223f24cc21540eac4c Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Tue, 10 Nov 2020 20:03:29 +0100 Subject: [PATCH 2/2] main.go: reload frontend on F5 --- main.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 49e4785..b795268 100644 --- a/main.go +++ b/main.go @@ -3,19 +3,28 @@ package main import ( "log" "net/http" + "strings" "github.com/rakyll/statik/fs" _ "github.com/fLotte-meets-HWR-DB/frontend/statik" ) +func strip(handler http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if !strings.Contains(r.URL.Path, ".") { + r.URL.Path = "/" + } + handler.ServeHTTP(w, r) + }) +} func main() { statikFS, err := fs.New() if err != nil { log.Fatal(err) } - // Serve the contents over HTTP. - http.Handle("/", http.FileServer(statikFS)) - log.Fatal(http.ListenAndServe(":8080", nil)) + m := http.NewServeMux() + m.Handle("/", strip(http.FileServer(statikFS))) + log.Fatal(http.ListenAndServe(":8080", m)) }