Merge pull request #24 from theoleuthardt/cors-fix

fix: configure docker compose and fastify cors with .env file
This commit is contained in:
Theo Leuthardt 2025-02-24 14:20:52 +01:00 committed by GitHub
commit 51befce05d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 23 additions and 13 deletions

7
.env Normal file
View file

@ -0,0 +1,7 @@
####### LOCAL DEVELOPMENT #######
NODE_ENV=development
HOSTNAME=0.0.0.0
FRONTEND_PORT=3000
BACKEND_PORT=4000
BACKEND=http://localhost:4000
CORS_ALLOWED_ORIGIN=http://localhost:3000

3
.gitignore vendored
View file

@ -32,7 +32,8 @@ yarn-error.log*
.pnpm-debug.log*
# env files (can opt-in for committing if needed)
.env*
frontend/.env
backend/.env
# vercel
.vercel

View file

@ -14,7 +14,7 @@ import { removeBG } from "./src/routes/removebg.route";
const app = Fastify({ logger: true });
app.register(cors, {
origin: "*",
origin: process.env.CORS_ALLOWED_ORIGIN || "*",
exposedHeaders: "Content-Disposition",
methods: "POST",
allowedHeaders: "Content-Type",

View file

@ -4,13 +4,14 @@ services:
context: ./frontend
dockerfile: Dockerfile
container_name: werkzeugkiste-frontend
env_file: .env
environment:
- NODE_ENV=production
- HOSTNAME=0.0.0.0
- PORT=3000
- backend_url=http://backend:4000
- NODE_ENV=${NODE_ENV}
- HOSTNAME=${HOSTNAME}
- PORT=${FRONTEND_PORT}
- BACKEND_URL=${BACKEND}
ports:
- "3000:3000"
- "${FRONTEND_PORT}:3000"
restart: unless-stopped
backend:
@ -18,13 +19,14 @@ services:
context: ./backend
dockerfile: Dockerfile
container_name: werkzeugkiste-backend
env_file: .env
environment:
- NODE_ENV=production
- HOSTNAME=0.0.0.0
- PORT=4000
- CORS_ORIGIN=http://frontend:3000
- NODE_ENV=${NODE_ENV}
- HOSTNAME=${HOSTNAME}
- PORT=${BACKEND_PORT}
- CORS_ALLOWED_ORIGIN=${CORS_ALLOWED_ORIGIN}
ports:
- "4000:4000"
- "${BACKEND_PORT}:4000"
restart: unless-stopped
networks:

View file

@ -3,7 +3,7 @@ import type { NextConfig } from "next";
const nextConfig: NextConfig = {
output: "standalone",
env: {
backend_url: "http://localhost:4000",
backend_url: process.env.BACKEND_URL || "http://localhost:4000",
},
};