-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (33 loc) · 1 KB
/
index.js
File metadata and controls
46 lines (33 loc) · 1 KB
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
const express = require("express")
const bodyParser = require("body-parser")
const KDTree = require("./service/kdtree")
const app = express()
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin","*");
res.header("Access-Control-Allow-Headers","*");
next();
});
const port = process.env.PORT || 3000
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.get('/', (req, res)=>{
console.log('My new endpoint')
res.send('Hello World')
})
app.post('/get-nearby', (req, res) => {
const points = req.body.locations
// Create a KDTree
const kdtree = new KDTree(points)
// Search for Nearest Location
const nearestLocation = kdtree.getNearestNeighbour({
x: req.body.currentLocation.latitude,
y: req.body.currentLocation.longitude
})
res.status(200).send({
latitude: nearestLocation.x,
longitude: nearestLocation.y
})
})
app.listen(port, () => {
console.log(`Server is up at ${port}.`);
})