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 cors from 'cors';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { initDB } from './db/index.js';
|
import { initDB } from './db/index.js';
|
||||||
import authRoutes from './routes/auth.js';
|
import authRoutes from './routes/auth.js';
|
||||||
@@ -37,12 +38,24 @@ app.get('/api/health', (req, res) => {
|
|||||||
|
|
||||||
// Serve static frontend files (for production)
|
// Serve static frontend files (for production)
|
||||||
const frontendPath = path.join(__dirname, '../../frontend/dist');
|
const frontendPath = path.join(__dirname, '../../frontend/dist');
|
||||||
app.use(express.static(frontendPath));
|
const frontendExists = fs.existsSync(frontendPath);
|
||||||
|
|
||||||
// Serve index.html for all non-API routes (SPA support)
|
if (frontendExists) {
|
||||||
app.get('*', (req, res) => {
|
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'));
|
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;
|
const PORT = process.env.PORT || 4000;
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|
||||||
web:
|
backend:
|
||||||
build: .
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile.dev
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
PORT: 4000
|
PORT: 4000
|
||||||
@@ -36,5 +38,20 @@ services:
|
|||||||
- ./backend:/app
|
- ./backend:/app
|
||||||
- /app/node_modules
|
- /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:
|
volumes:
|
||||||
db_data:
|
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