-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (44 loc) · 1.41 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
'use strict';
const Http = require('http');
const Qs = require('querystring');
const App = require('./app');
const Config = require('./config');
const Router = require('./router');
const Response = require('./response');
module.exports = class Server {
/**
* Main Server. This is a http v1 server.
*/
static httpV1() {
Http.createServer( (req, res) => {
let obj = new App(req, res);
let route = Router.fetchUrl(req, true);
if (!Router.validateRoute(route)) {
Response.write(res, App.error(null, 400), 400);
return false;
}
let method = route.split('/')[1].toLowerCase();
if (req.method === 'POST') {
let body = '';
req.on('data', (chunk) => {
body += chunk;
}).on('end', () => {
obj.initOSRM(method, Qs.parse(body));
return true;
});
} else if (req.method === 'GET') {
let data = Router.fetchUrl(req, false);
obj.initOSRM(method, data);
return true;
} else {
Response.write(res, App.error(null, 405), 405);
return false;
}
}).listen(Config.core.port);
}
/**
* Main Server. This is a http v2 server.
*/
static httpV2() {
}
};