-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
46 lines (33 loc) · 1.11 KB
/
app.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
45
46
//----------------------------------------------------------------
// SETUP
//----------------------------------------------------------------
require('dotenv').config();
const rp = require('request-promise');
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const PORT = process.env.API_PORT;
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({ type: 'application/*' })); //this is required for the contentful webhooks
const MS_USERS_API = process.env.MS_USERS_API;
const MS_STORIES_API = process.env.MS_STORIES_API;
app.use(cors());
app.get('/v1/story', async (req, res) => {
const result = await rp({
method: 'GET',
uri: `${MS_USERS_API}/story`,
json: true
});
res.json({ data: result });
})
app.get('/v1/users', async (req, res) => {
const result = await rp({
method: 'GET',
uri: `${MS_USERS_API}/users`,
json: true
});
res.json({ data: result });
})
app.listen(PORT, () => console.log(`Server listen port ${PORT}`));
module.exports = app;