-
Notifications
You must be signed in to change notification settings - Fork 28
/
express.js
48 lines (37 loc) · 1.35 KB
/
express.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
require('dotenv').config();
var compression = require('compression');
var express = require('express');
var keystone = require('keystone');
var morgan = require('morgan');
/**
* This is an example of creating a custom express app, binding the Admin UI
* router to it, and using Keystone to intialise the database connection
*/
var config = require('./config');
var app = new express();
keystone.init(config.options);
keystone.import('models');
keystone.set('locals', config.locals);
keystone.set('routes', require('./routes'));
keystone.set('nav', config.nav);
keystone.initDatabaseConfig();
keystone.initExpressSession();
app.use(compression());
app.use('/keystone', keystone.Admin.Server.createStaticRouter(keystone));
app.use(express.static('public'));
app.use(keystone.get('session options').cookieParser);
app.use(keystone.expressSession);
app.use(keystone.session.persist);
app.use(require('connect-flash')());
app.use(morgan('tiny'));
app.use('/keystone', keystone.Admin.Server.createDynamicRouter(keystone));
app.use(function (req, res) {
res.redirect('/keystone');
});
keystone.openDatabaseConnection(function () {
var server = app.listen(process.env.PORT || 3001, function () {
console.log('-------------------------------');
console.log('Express server ready on port %d', server.address().port);
console.log('-------------------------------');
});
});