diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..e8e1bb9 --- /dev/null +++ b/backend/Dockerfile @@ -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"] \ No newline at end of file diff --git a/backend/ormconfig.json b/backend/ormconfig.json index 83e4556..6033594 100644 --- a/backend/ormconfig.json +++ b/backend/ormconfig.json @@ -1,10 +1,12 @@ { "type": "sqlite", - "database": "./src/database/database.sqlite", + "database": "./database/database.sqlite", "migrations": [ + "./dist/database/migrations/*.js", "./src/database/migrations/*.ts" ], "entities": [ + "./dist/models/*.js", "./src/models/*.ts" ], "cli": { diff --git a/backend/src/server.ts b/backend/src/server.ts index 588175e..cac7270 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -10,7 +10,11 @@ import routes from './routes'; 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('/api', routes); diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 0000000..1052213 --- /dev/null +++ b/web/Dockerfile @@ -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}"] diff --git a/web/package.json b/web/package.json index 92c97fa..8f7320a 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "web", - "version": "0.1.0", + "version": "1.0.0", "private": true, "dependencies": { "@react-google-maps/api": "^2.1.1",