Merge pull request #2 from fLotte-meets-HWR-DB/frontend_server

Frontend server
pull/3/head
leonnicolas 4 years ago committed by GitHub
commit 72269f0f27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,12 +1,12 @@
FROM node:14.14.0-alpine3.10 AS builder FROM node:14.14.0-alpine3.10 AS builder
WORKDIR / WORKDIR /
COPY package.json package-lock.json ./ 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 RUN mv node_modules ./frontend
WORKDIR /frontend WORKDIR /frontend
COPY . . COPY . .
RUN npm run ng build --prod --crossOrigin=anonymous RUN ng build --prod --crossOrigin=anonymous
FROM golang:1.13.4-alpine as builder2 FROM golang:1.13.4-alpine as builder2
RUN apk add git RUN apk add git
@ -15,7 +15,7 @@ COPY --from=builder /frontend/dist /dist
RUN go get github.com/rakyll/statik RUN go get github.com/rakyll/statik
RUN statik --src=/dist/flotte-frontend RUN statik --src=/dist/flotte-frontend
COPY *.go *.sum *.mod / COPY *.go *.sum *.mod /
COPY vendor ./vendor COPY vendor /vendor
RUN CGO_ENABLED=0 GOOS=linux go build --mod=vendor -o frontend_server RUN CGO_ENABLED=0 GOOS=linux go build --mod=vendor -o frontend_server
FROM scratch FROM scratch

@ -3,19 +3,28 @@ package main
import ( import (
"log" "log"
"net/http" "net/http"
"strings"
"github.com/rakyll/statik/fs" "github.com/rakyll/statik/fs"
_ "github.com/fLotte-meets-HWR-DB/frontend/statik" _ "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() { func main() {
statikFS, err := fs.New() statikFS, err := fs.New()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
// Serve the contents over HTTP. m := http.NewServeMux()
http.Handle("/", http.FileServer(statikFS)) m.Handle("/", strip(http.FileServer(statikFS)))
log.Fatal(http.ListenAndServe(":8080", nil)) log.Fatal(http.ListenAndServe(":8080", m))
} }

Loading…
Cancel
Save