-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.js
48 lines (40 loc) · 1.35 KB
/
web.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
var express = require("express");
var app = express();
var path = require('path');
var lessMiddlware = require('less-middleware');
var http = require('http');
var model = require('./lib/model');
var url = require('url');
var Conf = require('./config'),
config = new Conf();
var dbOptions = config.db;
// Initialize the models.
// model.js is in lib/ and models should be in models/
model.setup('./models', dbOptions.name, dbOptions.user, dbOptions.pass, dbOptions);
model.seq().sync().success(function () {
console.log('Database synced!');
}).error(function (error) {
console.log('Sync failed: ' + error);
});
app.configure(function () {
app.set('port', process.env.PORT || 5000);
app.set('rootUrl', '/api');
app.use(express.bodyParser());
app.use(express.logger('dev'));
app.use(lessMiddlware({
src: __dirname + '/public',
compress: true
}));
app.use(express.static(path.join(__dirname, '/public')));
});
/* Load routes from ./routes/ subdirectory. */
['guide', 'place', 'category', 'location'].forEach(function (element) {
require('./routes/' + element)(app);
});
/* Default to serving index.html and let Backbone handle route. */
app.use(function(req, res) {
res.sendfile('./public/index.html');
});
http.createServer(app).listen(app.get('port'), function() {
console.log('Listening on ' + app.get('port'));
});