feat: add backend setup with Express and unit tests
Backend Foundation (Phase 1 - Step 1):
**Infrastructure:**
- Add backend service to docker-compose.yml
- Configure nginx to proxy /api/* to backend
- Node.js 20 Alpine Docker container
**Backend Setup:**
- Express.js REST API server
- CORS configuration
- Request logging middleware
- Error handling (404, 500)
- Graceful shutdown on SIGTERM/SIGINT
- Health check endpoint: GET /api/health
**Testing:**
- Jest + Supertest for unit tests
- 7 test cases covering:
- Health check endpoint
- 404 error handling
- CORS headers
- JSON body parsing
- Code coverage: 88.23%
**Project Structure:**
- backend/src/app.js - Express app setup
- backend/src/server.js - Server entry point
- backend/src/__tests__/ - Unit tests
- backend/README.md - Backend documentation
**Environment:**
- .env.example template
- Development configuration
- Ready for PostgreSQL integration
All tests passing ✅
This commit is contained in:
31
backend/src/server.js
Normal file
31
backend/src/server.js
Normal file
@@ -0,0 +1,31 @@
|
||||
require('dotenv').config();
|
||||
const app = require('./app');
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
const server = app.listen(PORT, '0.0.0.0', () => {
|
||||
console.log('=================================');
|
||||
console.log('🚀 spotlight.cam Backend Started');
|
||||
console.log('=================================');
|
||||
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`);
|
||||
console.log(`Server running on port: ${PORT}`);
|
||||
console.log(`Health check: http://localhost:${PORT}/api/health`);
|
||||
console.log('=================================');
|
||||
});
|
||||
|
||||
// Graceful shutdown
|
||||
process.on('SIGTERM', () => {
|
||||
console.log('SIGTERM received, shutting down gracefully...');
|
||||
server.close(() => {
|
||||
console.log('Server closed');
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
console.log('SIGINT received, shutting down gracefully...');
|
||||
server.close(() => {
|
||||
console.log('Server closed');
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user