-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
81 lines (64 loc) · 2.11 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
69
70
71
72
73
74
75
76
77
78
79
80
81
require('newrelic');
var http = require('http');
var https = require('https');
var express = require('express');
var path = require('path');
var app = express();
var logger = require('morgan');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var session = require('express-session');
var multer = require('multer');
var CronJob = require('cron').CronJob;
var jwt = require("jsonwebtoken");
var mongoose = require("mongoose");
var mongoose = require('mongoose');
mongoose.connect(process.env.MONGOLAB_URI || 'mongodb://localhost/hotelsDB');
var db = mongoose.connection;
var updateHotels = require('./saveAllHotels');
var routes = require('./app/api/routes/bookings');
//environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev')); // log every request to the console
app.use(bodyParser.urlencoded({
extended: true
})); // parse application/x-www-form-urlencoded
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
next();
});
app.use(session({
resave: true,
saveUninitialized: true,
secret: 'uwotm8'
}));
app.use(bodyParser.json()) // parse application/json
app.use(methodOverride()); // simulate DELETE and PUT
// app.use(multer());
app.use(express.static(path.join(__dirname, './public')));
var server = app.listen((process.env.PORT || 3000), function() {
var host = server.address().address;
var port = server.address().port;
console.log('Your app is running on localhost port 3000');
});
var router = express.Router(); // get an instance of the express Router
routes(app);
var env = process.env.NODE_ENV || 'development';
if ('development' == env) {
}
var job = new CronJob({
cronTime: '00 15 11 * * 0-6',
onTick: function() {
console.log('run');
updateHotels();
},
start: false
});
job.start();
setInterval(function() {
https.get("/api/saveAllHotels");
}, 300000);