Skip to content

Commit

Permalink
Merge pull request #29 from FachschaftMathPhysInfo/19-dockerize-front…
Browse files Browse the repository at this point in the history
…end-and-proxy-in-front-of-both

19 dockerize frontend and proxy in front of both
  • Loading branch information
dheidemann authored Jul 7, 2024
2 parents d1137b2 + e76075b commit 51ec993
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ SMTP_PASSWORD=
SMTP_PORT=
FROM_ADDRESS=

API_URL=http://localhost:8080
URL=http://localhost:8080

API_KEY=
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ services:
- 8080:8080
depends_on:
- postgres
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
restart: always
env_file: .env.local
depends_on:
- server
2 changes: 2 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.next
15 changes: 15 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:22-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build

EXPOSE 3000

CMD [ "npm", "start" ]
3 changes: 2 additions & 1 deletion server/email/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func SendConfirmation(person models.User) error {
Color: "#990000",
Text: "E-Mail bestätigen",
Link: fmt.Sprintf("%s/confirm/%s",
os.Getenv("API_URL"), strconv.Itoa(person.SessionID)),
os.Getenv("URL"), strconv.Itoa(person.SessionID)),
},
},
},
Expand All @@ -45,6 +45,7 @@ func SendConfirmation(person models.User) error {
},
},
}

from := os.Getenv("FROM_ADDRESS")
smtpHost := os.Getenv("SMTP_HOST")
smtpUser := os.Getenv("SMTP_USER")
Expand Down
13 changes: 10 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"

"github.com/99designs/gqlgen/graphql/handler"
Expand Down Expand Up @@ -51,9 +53,10 @@ func main() {
defer c.Stop()

// server configuration
// [/]: GraphQL Playground
// [/]: Next.JS frontend
// [/api]: JSON API endpoint
// [/confirm/{email}]: Confirm email addresses
// [/playground]: GraphQL Playground
// [/confirm/{sessionID}]: Confirm email addresses
router := chi.NewRouter()
router.Use(cors.New(cors.Options{
AllowedHeaders: []string{"*"},
Expand All @@ -63,6 +66,10 @@ func main() {

router.Use(middleware.Logger)

frontendUrl, _ := url.Parse("http://frontend:3000")
proxy := httputil.NewSingleHostReverseProxy(frontendUrl)
router.Handle("/*", proxy)

router.Get("/confirm/{sessionID}", func(w http.ResponseWriter, r *http.Request) {
email.Confirm(ctx, w, r, db)
})
Expand All @@ -79,7 +86,7 @@ func main() {
})
}).Handle("/api", srv)

router.Handle("/", playground.Handler("GraphQL playground", "/api"))
router.Handle("/playground", playground.Handler("GraphQL playground", "/api"))

log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, router))
Expand Down

0 comments on commit 51ec993

Please sign in to comment.