feat: implement dockerfiles and improve cors configuration

This commit is contained in:
2025-11-17 14:20:04 -03:00
parent 70baa4997a
commit 038dbcb4ea
5 changed files with 59 additions and 3 deletions

34
backend/Dockerfile Normal file
View File

@@ -0,0 +1,34 @@
##### Builder stage ###########################################################
FROM node:18-slim AS builder
WORKDIR /app
# Install dependencies (dev + prod) so we can build TypeScript
COPY package.json yarn.lock ormconfig.json ./
RUN yarn install --frozen-lockfile
# Build TypeScript -> dist
COPY . .
RUN yarn build
# Prune to production dependencies only (keeps sqlite3 from dependencies)
RUN yarn install --frozen-lockfile --production
##### Runtime stage ###########################################################
FROM node:18-slim
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3101
# Copy compiled app and production node_modules from builder
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/ormconfig.json ./
RUN mkdir -p /app/uploads /app/database
# Include the sqlite database that migrations already prepared
COPY --from=builder /app/src/database/database.sqlite ./database/
EXPOSE 3101
CMD ["node", "dist/server.js"]

View File

@@ -1,10 +1,12 @@
{ {
"type": "sqlite", "type": "sqlite",
"database": "./src/database/database.sqlite", "database": "./database/database.sqlite",
"migrations": [ "migrations": [
"./dist/database/migrations/*.js",
"./src/database/migrations/*.ts" "./src/database/migrations/*.ts"
], ],
"entities": [ "entities": [
"./dist/models/*.js",
"./src/models/*.ts" "./src/models/*.ts"
], ],
"cli": { "cli": {

View File

@@ -10,7 +10,11 @@ import routes from './routes';
const app = express(); const app = express();
app.use(cors()); const allowedOrigins = (process.env.CORS_ORIGIN || 'http://localhost:3000')
.split(',')
.map(origin => origin.trim());
app.use(cors({ origin: allowedOrigins }));
app.use(express.json()); app.use(express.json());
app.use('/api', routes); app.use('/api', routes);

16
web/Dockerfile Normal file
View File

@@ -0,0 +1,16 @@
# Builder stage
FROM node:16-alpine AS builder
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --production --frozen-lockfile
COPY . .
RUN yarn build
# Runtime stage
FROM node:16-alpine
WORKDIR /app
COPY --from=builder /app/build ./build
RUN yarn global add serve
ENV PORT=3000
EXPOSE 3000
CMD ["sh", "-c", "serve -s build -l ${PORT}"]

View File

@@ -1,6 +1,6 @@
{ {
"name": "web", "name": "web",
"version": "0.1.0", "version": "1.0.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@react-google-maps/api": "^2.1.1", "@react-google-maps/api": "^2.1.1",