-
Notifications
You must be signed in to change notification settings - Fork 16
/
server.js
76 lines (66 loc) · 2.01 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Created by xinzheng on 1/24/17.
*/
require('dotenv').config();
const express = require('express');
const fetch = require('node-fetch');
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 8000;
const publicMainNOLA_path = express.static(__dirname + '/public');
app.use(publicMainNOLA_path);
app.use(bodyParser.json()); // for parsing application/json
app.post('/api', function (request, response) {
fetch("https://analysis.conveyal.com/api/analysis", {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": process.env.API_TOKEN,
},
body: JSON.stringify(
request.body
)
})
.then(res => res.buffer())
.then(buffer => response.send(buffer))
});
app.post('/grid', function (request, response) {
let id = request.body.opportunityDatasetId;
fetch("https://analysis.conveyal.com/api/opportunities/" + id, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"Authorization": process.env.API_TOKEN,
},
})
.then(res => response.json({url: res.url}));
});
app.post('/getModifications', function (request, response) {
let projectID = request.body.projectID;
fetch("https://analysis.conveyal.com/api/project/" + projectID + "/modifications", {
method: 'GET',
headers: {
"Content-Type": "application/json",
"Authorization": process.env.API_TOKEN,
},
})
.then(res => res.buffer())
.then(buffer => response.send(buffer))
});
app.post('/updateModifications', function (request, response) {
let modificationID = request.body.newModification._id;
fetch("https://analysis.conveyal.com/api/modification/" + modificationID, {
method: 'PUT',
headers: {
"Content-Type": "application/json",
"Authorization": process.env.API_TOKEN,
},
body: JSON.stringify(
request.body.newModification
)
})
.then(res => response.send(res))
});
app.listen(port, function () {
console.log("App is running on port " + port);
});