split containers
This commit is contained in:
12
Dockerfile.dev
Normal file
12
Dockerfile.dev
Normal file
@@ -0,0 +1,12 @@
|
||||
FROM node:18-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY backend/package*.json ./
|
||||
RUN npm install
|
||||
|
||||
COPY backend/ ./
|
||||
|
||||
EXPOSE 4000
|
||||
|
||||
CMD ["node", "src/index.js"]
|
||||
@@ -2,6 +2,7 @@ import express from 'express';
|
||||
import cors from 'cors';
|
||||
import dotenv from 'dotenv';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { initDB } from './db/index.js';
|
||||
import authRoutes from './routes/auth.js';
|
||||
@@ -37,12 +38,24 @@ app.get('/api/health', (req, res) => {
|
||||
|
||||
// Serve static frontend files (for production)
|
||||
const frontendPath = path.join(__dirname, '../../frontend/dist');
|
||||
const frontendExists = fs.existsSync(frontendPath);
|
||||
|
||||
if (frontendExists) {
|
||||
app.use(express.static(frontendPath));
|
||||
|
||||
// Serve index.html for all non-API routes (SPA support)
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(frontendPath, 'index.html'));
|
||||
});
|
||||
} else {
|
||||
console.log('ℹ️ Frontend dist not found - running in API-only mode (dev)');
|
||||
app.get('*', (req, res) => {
|
||||
res.json({
|
||||
message: "What's The Point API - Frontend running separately",
|
||||
frontend: "http://localhost:5173"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const PORT = process.env.PORT || 4000;
|
||||
|
||||
|
||||
@@ -16,8 +16,10 @@ services:
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
web:
|
||||
build: .
|
||||
backend:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.dev
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
PORT: 4000
|
||||
@@ -36,5 +38,20 @@ services:
|
||||
- ./backend:/app
|
||||
- /app/node_modules
|
||||
|
||||
frontend:
|
||||
build:
|
||||
context: ./frontend
|
||||
dockerfile: Dockerfile.dev
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
VITE_API_URL: http://localhost:4000/api
|
||||
depends_on:
|
||||
- backend
|
||||
ports:
|
||||
- "5173:5173"
|
||||
volumes:
|
||||
- ./frontend:/app
|
||||
- /app/node_modules
|
||||
|
||||
volumes:
|
||||
db_data:
|
||||
|
||||
12
frontend/Dockerfile.dev
Normal file
12
frontend/Dockerfile.dev
Normal file
@@ -0,0 +1,12 @@
|
||||
FROM node:18-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 5173
|
||||
|
||||
CMD ["npm", "run", "dev"]
|
||||
Reference in New Issue
Block a user