This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
server.js
68 lines (57 loc) · 1.71 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
const express = require('express');
const path = require('path');
const api = require('./api');
const areaApi = require('./area');
const cors = require("cors");
/**
* Inits Database and triggers seeding if no database exists
* @constructor
* @param {int} port - Portnumber
*/
function init(port) {
const app = express();
app.set('port', (port ||process.env.PORT || 5000))
app.use(cors({
origin: '*'
}));
app.get('/', (request, response) => {
response.sendFile(path.join(__dirname + '/index.html'));
});
app.get('/getLastPositionFromVF/:mmsi', (req, res) => {
api.getLocationFromVF(req.params.mmsi, (result) => {
res.send(result);
});
});
app.get('/getLastPositionFromMT/:mmsi', (req, res) => {
api.getLocationFromMT(req.params.mmsi, (result) => {
res.send(result);
});
});
app.get('/getLastPosition/:mmsi', (req, res) => {
api.getLocation(req.params.mmsi, (result) => {
res.send(result);
});
});
// e.g. /getVesselsInArea/WMED,EMED
app.get('/getVesselsInArea/:area', async (req, res) => {
const result = await areaApi.fetchVesselsInArea(req.params.area.split(','), (result) => {
res.json(result);
});
});
app.get('/getVesselsNearMe/:lat/:lng/:distance', async (req, res) => {
const result = await areaApi.fetchVesselsNearMe(req.params.lat, req.params.lng, req.params.distance, (result) => {
res.json(result);
});
});
app.get('/getVesselsInPort/:shipPort', (req, res) => {
api.getVesselsInPort(req.params.shipPort, (result) => {
res.send(result);
});
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
}
module.exports = {
init: init,
};