forked from danceoval/1702-tp-static
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (39 loc) · 1.34 KB
/
app.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
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var nunjucks = require('nunjucks');
var models = require('./models');
var router = require('./routes');
var app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.use('/bootstrap', express.static(path.join(__dirname, 'bower_components/bootstrap/dist')));
app.use('/jquery', express.static(path.join(__dirname, 'bower_components/jquery/dist')));
app.use(bodyParser.urlencoded({extended : true}));
app.use(bodyParser.json());
app.use(morgan('dev'))
app.set('view engine', 'html');
app.engine('html', nunjucks.render);
var env = nunjucks.configure('views', {noCache: true});
var AutoEscapeExtension = require('nunjucks-autoescape')(nunjucks);
env.addExtension('AutoEscapeExtension', new AutoEscapeExtension(env));
app.use('/', router);
// catch 404 (i.e., no route was hit) and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// handle all errors (anything passed into `next()`)
app.use(function(err, req, res, next) {
res.status(err.status || 500);
console.error(err);
res.render(
// ... fill in this part
);
});
models.db.sync()
.then(
app.listen(3000, function(){
console.log("Listening on 3000")
}));