-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
36 lines (29 loc) · 881 Bytes
/
app.js
File metadata and controls
36 lines (29 loc) · 881 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 express = require("express");
const path = require("path");
const favicon = require("serve-favicon");
const bodyParser = require("body-parser");
const port = 3000;
const cors = require("cors");
const app = express();
const bikes = require("./server/api/bikeapi")
app.use(bodyParser.json());
app.use(cors())
app.use("/api/", bikes)
app.listen(port, function () {
console.log(`My server is listening on port ${port}!`)
})
// 404 will be forwarded to error handler
app.use(function (request, response, next) {
const error = new Error("Page not found.");
error.status = 404;
next(error);
})
// Error handler
app.use(function (error, request, response, next) {
response.status(error.status || 500);
response.json({
message: error.message,
error: request.app.get('env') === 'development' ? error : {}
});
});
module.exports = app;