-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (39 loc) · 1.37 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
var app = require('express')(),swig = require('swig'),people;
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
/* My Library */
var fun = require('./funclib');
var routes = require('./routes');
// This is where all the magic happens!
app.engine('html', swig.renderFile);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// Swig will cache templates for you, but you can disable
// that and use Express's caching instead, if you like:
app.set('view cache', false);
// To disable Swig's cache, do the following:
swig.setDefaults({ cache: false });
// NOTE: You should always cache templates in a production environment.
// Don't leave both of these to `false` in production!
app.get('/', routes.route);
app.get('/post', routes.post);
app.get('/list', routes.list);
// Handle 404
app.use(function(req, res) {
res.send('404: Page not Found', 404);
});
// Handle 500
app.use(function(error, req, res, next) {
res.send('500: Internal Server Error', 500);
});
app.listen(3000);
console.log('Application Started');