-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (34 loc) · 981 Bytes
/
index.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
// Libraries
const express = require('express')
const cors = require('cors')
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
// Constants
const app = express()
const port = process.env.PORT || 8000
const CMM_URI = "https://ceumass.eps.uspceu.es/mediator/api/v3/batch";
// Middlewares
app.use(express.json());
app.use(cors());
// Routing
app.get('/', (req, res) => {
res.send('Fetch CMM API')
})
app.post('/get_cmm', async (req, res) => {
const resCMM = await new Promise(res => {
fetch(
CMM_URI,
{
method: 'POST',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(req.body)
}
).then(value => res(value));
});
const resCMMJson = await resCMM.json();
res.json(resCMMJson);
});
app.listen(port, () => {
console.log(`fetchCMM app listening on port ${port}`)
})