-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (39 loc) · 1.19 KB
/
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
39
40
41
42
43
44
const express = require('express');
const app = express();
const port = 3300;
app.get('/message', function (req, res) {
res.send({'message': 'This is the message'});
});
app.get('/media', function (req, res) {
let response = {
podcasts: [{
"description": "some text",
"id": 574,
"title": "Why long-term value is a winning bet",
"media": "podcast",
"publishedDate": "2018-12-19T18:00:00.000Z",
"isLive": true,
"isDeleted": false,
"link": "https://podcasts.com/574",
"createdAt": "2018-12-20T06:30:00.618Z",
"updatedAt": "2019-01-31T06:30:00.864Z"
}],
total: 1
}
if (response.podcasts.length > 0) {
res.send(response);
} else {
let errorObj = {
httpCode: 404,
message: 'NOT_FOUND',
description: 'The resource referenced by request does not exists.',
details: 'Podcast is not available'
}
res.status(404);
res.send(errorObj)
}
});
app.listen(port, function () {
console.log("\nServer is running on port " + port);
});
module.exports = app; // for testing