-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (30 loc) · 893 Bytes
/
Copy pathserver.js
File metadata and controls
36 lines (30 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
const middlewares = jsonServer.defaults();
const cors = require('cors');
server.use(cors());
server.use(middlewares);
server.get('/', (req, res) => {
res.json({
status: 'OK',
message: 'SpicX API is running',
endpoints: {
products: '/products',
users: '/users',
carts: '/carts'
}
});
});
server.use(router);
const port = process.env.PORT || 8000;
server.listen(port, () => {
console.log(`✅ JSON Server is running on port ${port}`);
console.log(`📦 Database: db.json`);
console.log(`🚀 API URL: http://localhost:${port}`);
console.log('🔄 Server is stable and waiting for connections...');
});
process.on('SIGTERM', () => {
console.log('Received SIGTERM, shutting down gracefully');
process.exit(0);
});