-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServer.js
More file actions
36 lines (33 loc) · 1.09 KB
/
Copy pathServer.js
File metadata and controls
36 lines (33 loc) · 1.09 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
var express = require('express');
var utilities = require('./serverUtility');
var app= express();
app.use(express.static(__dirname + '/'));
var bodyParser = require('body-parser');
var multer = require('multer');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(multer());
var port = 8080;
var server=app.listen(port, function() {
var host = server.address().address;
var port = server.address().port;
console.log('server listening on port ' + port+host);
});
app.post('/getPath', function (req, res) {
console.log("Got request on node to calculate path");
var path,tPath,robotPos,currAlgo;
path=req.body.path;
robotPos=req.body.robotPos;
currAlgo=req.body.algo;
if(currAlgo=="Greedy"){
path=utilities.sortDistanceWise(robotPos,path);
tPath=utilities.calculateThePath(path);
console.log("Sending Response Back");
res.json(tPath);
}else{
path=utilities.bruteForce(robotPos,path);
tPath=utilities.calculateThePath(path);
console.log("Sending Response Back");
res.json(tPath);
}
});