-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (32 loc) · 870 Bytes
/
server.js
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
37
38
const express = require("express");
const mockData = require("./mockData.js");
const app = express();
const port = process.env.PORT || 5000;
app.use(function(err, req, res, next) {
res.status(err.status || 500).json(response.error(err.status || 500));
});
function mockAsync(cb, ms) {
setTimeout(function() {
let err = null;
cb(err);
}, ms);
}
function mockAsyncErr(cb, ms) {
setTimeout(function() {
let err = new Error("mock async error");
cb(err);
}, ms);
}
app.get("/phones", (req, res, next) => {
mockAsync(function(err) {
if (err) return next(err);
res.send({ payload: mockData });
}, 2000);
});
app.get("/phonesErr", (req, res, next) => {
mockAsyncErr(function(err) {
if (err) return next(err);
res.send({ payload: mockData });
}, 2000);
});
app.listen(port, () => console.log(`Listening on port ${port}`));