-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (41 loc) · 1.13 KB
/
index.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
const Hapi = require('hapi');
const cron = require('cron');
const Inert = require('inert');
//carica tutte le routes di routes.js
var routes = require('./routes.js');
var dbHandler = require('./backEnd/dbHandler.js');
var webScraper = require('./backEnd/scraper.js');
const Path = require('path');
const server = new Hapi.Server({
connections: {
routes: {
files: {
relativeTo: Path.join(__dirname, 'frontEnd')
}
}
}
});
server.connection({ port: 8081 });
server.register(Inert, () => {});
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
if(dbHandler.dbExist()){
dbHandler.getValues();
}
else {
webScraper.scanSite(function(itinerari, localita){
dbHandler.rebuildDB(itinerari, localita);
dbHandler.getValues();
});
}
cron.job("30 30 8 * * Sun", function(){
webScraper.scanSite(function(itinerari, localita){
dbHandler.rebuildDB(itinerari, localita);
dbHandler.getValues();
});
}).start();
});
server.route(routes);