diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..82e6df7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +**/node_modules/ +**/dist/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3ecfdd1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ministream-frontend"] + path = ministream-frontend + url = ssh://git@git.t-juice.club:222/torjus/ministream-frontend.git diff --git a/Dockerfile b/Dockerfile index 78098a3..9a53566 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,20 @@ +FROM node:latest as frontend-builder +WORKDIR /app +COPY ministream-frontend/package-lock.json /app/package-lock.json +COPY ministream-frontend/package.json /app/package.json +COPY ministream-frontend/tsconfig.json /app/tsconfig.json +RUN npm install +COPY ministream-frontend/src /app/src +RUN npm run-script build + FROM golang:alpine as builder WORKDIR /app COPY go.mod /app/go.mod COPY go.sum /app/go.sum RUN go mod download -COPY . /app +COPY --from=frontend-builder /app/dist /app/server/static +COPY main.go /app +COPY server /app/server RUN go build -o ministream main.go FROM alpine:latest diff --git a/ministream-frontend b/ministream-frontend new file mode 160000 index 0000000..e26f555 --- /dev/null +++ b/ministream-frontend @@ -0,0 +1 @@ +Subproject commit e26f5553007c43d87dd641149e1368e0360827c9 diff --git a/server/server.go b/server/server.go index 29b174e..7ce2f9f 100644 --- a/server/server.go +++ b/server/server.go @@ -31,6 +31,7 @@ func NewServer(store *UserStore) *Server { } r := chi.NewRouter() + r.Use(corsMiddleware) r.Get("/", srv.StaticHandler) r.Get("/{name}", srv.StaticHandler) r.Post("/whip", http.HandlerFunc(srv.WhipHandler)) @@ -45,6 +46,14 @@ func NewServer(store *UserStore) *Server { return srv } +func corsMiddleware(next http.Handler) http.Handler { + fn := func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Access-Control-Allow-Origin", "*") + next.ServeHTTP(w, r) + } + return http.HandlerFunc(fn) +} + func (s *Server) OptionsHandler(w http.ResponseWriter, r *http.Request) { slog.Info("Got OPTIONS") } diff --git a/server/static/index.html b/server/static/index.html index 0ce8593..fd28b43 100644 --- a/server/static/index.html +++ b/server/static/index.html @@ -1,15 +1,12 @@ - + -
+ + -