-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
57 lines (42 loc) · 1.21 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
var Express = require('express');
var fs = require('fs');
var cors = require('cors')
//istanzio express
var app = Express();
app.use(cors());
app.use(Express.static('public'));
//prendo l'istanza del router da express'
var router = Express.Router();
router.get('/menu', function(req, res){
fs.readFile('./data/menu.json',function(err, data){
if(err) res.send('error');
else {
var jsonMenu = JSON.parse(data);
res.send(jsonMenu);
}
});
});
router.get('/parcheggi', function(req, res){
fs.readFile('./data/parcheggi.json',function(err, data){
if(err) res.send('error');
else res.send(JSON.parse(data));
});
});
router.get('/ztl', function(req, res){
fs.readFile('./data/ztl.json',function(err, data){
if(err) res.send('error');
else res.send(JSON.parse(data));
});
});
router.get('/incidenti', function(req, res){
fs.readFile('./data/incidenti.json',function(err, data){
if(err) res.send('error');
else res.send(JSON.parse(data));
});
});
//registro le rotte
app.use('/geodata', router);
//metto in ascolto express
app.listen(5000, () => {
console.log('Awaiting on port 5000');
});