forked from ironhack-labs/json-server-backend
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
26 lines (22 loc) · 643 Bytes
/
app.js
File metadata and controls
26 lines (22 loc) · 643 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
try {
process.loadEnvFile();
} catch (e) {
console.warn(".env file not found, using default values.");
}
const jsonServer = require("json-server");
const morgan = require("morgan");
const server = jsonServer.create();
const router = jsonServer.router("db.json");
const middlewares = jsonServer.defaults();
const PORT = process.env.PORT || 5005;
server.use(middlewares);
server.use(morgan("dev"));
server.use((req, res, next) => {
// Middleware to disable CORS
res.header("Access-Control-Allow-Origin", "*");
next();
});
server.use(router);
server.listen(PORT, () => {
console.log(`JSON Server is running at port ${PORT}`);
});