small prod changes
All checks were successful
Release Build / build-docker (push) Successful in 43s
Release Build / build-android-and-release (push) Successful in 2m11s

This commit is contained in:
Rene Kievits
2025-12-24 16:20:44 +01:00
parent ac225b5b41
commit e1bf8f2032
9 changed files with 93 additions and 41 deletions

View File

@@ -22,6 +22,7 @@ jobs:
run: | run: |
cd client cd client
docker build \ docker build \
--target production-stage \
--build-arg VITE_API_URL=${{ vars.VITE_API_URL }} \ --build-arg VITE_API_URL=${{ vars.VITE_API_URL }} \
-t ${{ vars.REGISTRY_URL }}/zen-kanji-client:latest . -t ${{ vars.REGISTRY_URL }}/zen-kanji-client:latest .
docker push ${{ vars.REGISTRY_URL }}/zen-kanji-client:latest docker push ${{ vars.REGISTRY_URL }}/zen-kanji-client:latest

View File

@@ -1,15 +1,31 @@
FROM node:24-alpine AS dev-stage # Stage 1: Build the Application
FROM node:20-alpine AS build-stage
WORKDIR /app WORKDIR /app
ARG VITE_API_URL
ENV VITE_API_URL=$VITE_API_URL
COPY package*.json ./ COPY package*.json ./
RUN npm ci RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine AS dev-stage
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . . COPY . .
EXPOSE 5173 EXPOSE 5173
CMD ["npm", "run", "dev", "--", "--host"] CMD ["npm", "run", "dev", "--", "--host"]
FROM dev-stage AS build-stage FROM nginx:alpine AS production-stage
ARG VITE_API_URL RUN mkdir -p /run/nginx
ENV VITE_API_URL=$VITE_API_URL
RUN npm run build COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -5,7 +5,7 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"> <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Zen Kanji</title> <title>Zen Kanji</title>
<link rel="icon" type="image/x-icon" href="/assets/favicon.ico"> <link rel="icon" type="image/x-icon" href="/src/assets/favicon.ico">
</head> </head>
<body> <body>

16
client/nginx.conf Normal file
View File

@@ -0,0 +1,16 @@
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, no-transform";
}
}

View File

@@ -18,15 +18,15 @@ export default defineConfig(({ mode }) => {
}, },
server: { server: {
allowedHosts: [ allowedHosts: [
env.VITE_HOST, 'localhost',
], ],
host: true, host: true,
port: 5173, port: 5173,
strictPort: true, strictPort: true,
hmr: { hmr: {
host: env.VITE_HOST, host: 'localhost',
protocol: 'wss', protocol: 'ws',
clientPort: 443, clientPort: 5173,
}, },
}, },
}; };

33
docker-compose.dev.yml Normal file
View File

@@ -0,0 +1,33 @@
services:
mongo:
image: mongo:6
container_name: zen_mongo
restart: always
ports:
- "27017:27017"
volumes:
- mongo-data:/data/db
networks:
- zen-network
server:
depends_on:
- mongo
environment:
- MONGO_URI=mongodb://mongo:27017/zenkanji
volumes:
- ./server:/app
- /app/node_modules
ports:
- "3000:3000"
command: npm run dev
client:
build:
target: dev-stage
ports:
- "5173:5173"
volumes:
- ./client:/app
- /app/node_modules
command: npm run dev -- --host

0
docker-compose.prod.yml Normal file
View File

View File

@@ -1,47 +1,23 @@
services: services:
mongo:
image: mongo:6
container_name: zen_mongo
restart: always
ports:
- "27017:27017"
volumes:
- mongo-data:/data/db
networks:
- zen-network
server: server:
build: ./server build:
context: ./server
container_name: zen_server container_name: zen_server
restart: always
ports:
- "3000:3000"
env_file: env_file:
- .env - ./server/.env
depends_on:
- mongo
networks: networks:
- zen-network - zen-network
volumes:
- ./server:/app
- /app/node_modules
client: client:
build: build:
context: ./client context: ./client
target: dev-stage
container_name: zen_client container_name: zen_client
ports:
- "5173:5173"
env_file: env_file:
- .env - ./client/.env
depends_on: depends_on:
- server - server
networks: networks:
- zen-network - zen-network
volumes:
- ./client:/app
- /app/node_modules
volumes: volumes:
mongo-data: mongo-data:

View File

@@ -17,10 +17,20 @@ const allowedOrigins = [
'capacitor://localhost', 'capacitor://localhost',
'https://10.0.2.2:5173', 'https://10.0.2.2:5173',
'http://localhost:5173' 'http://localhost:5173'
]; ].filter(Boolean).map(uri => uri.replace(/\/$/, ''));
await fastify.register(cors, { await fastify.register(cors, {
origin: allowedOrigins, origin: (origin, cb) => {
if (!origin) return cb(null, true);
if (allowedOrigins.includes(origin)) {
return cb(null, true);
}
console.log(`CORS BLOCKED: Browser sent "${origin}". Allowed list:`, allowedOrigins);
cb(new Error("Not allowed by CORS"));
},
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
credentials: true credentials: true
}); });