-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (28 loc) · 942 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
// server only exists to circumvent CORS restriction
const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const fetch = require("node-fetch");
const app = express();
const useMockData = true;
app.use(bodyParser.text());
app.get("/", (req, res) => res.sendFile(path.join(__dirname, "public/index.html")));
app.get("/*", (req, res) => {
const filePath = path.join(__dirname, "public", req.url);
res.sendFile(filePath);
});
app.post("/data", (req, res) => {
console.log(`processing query\n${req.body}`);
if (useMockData) {
const filePath = path.join(__dirname, "mockData/basicQuery.xml");
res.sendFile(filePath);
}else {
fetch("https://lz4.overpass-api.de/api/interpreter", {
body: req.body,
method: "post",
})
.then(OSMResp => OSMResp.text())
.then(text => res.send(text));
}
});
app.listen(3000, () => console.log("Example app listening on port 3000!"));