forked from sophiahuxh/wmb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeystone.js
103 lines (81 loc) · 2.63 KB
/
keystone.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Simulate config options from your production environment by
// customising the .env file in your project's root folder.
require('dotenv').config();
// Require keystone
var keystone = require('keystone');
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');
// var ships = require('./routes/views/ship');
// var test = require('./routes/views/ships');
// var fields = require('./routes/views/fields');
var mongo = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/jsgrid-keystone');
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// app.use(express.cookieParser('+crypto.randomBytes(64)+'));
// app.use(express.session());
app.use(express.static(path.join(__dirname, 'public')));
app.use(function(req,res,next){
req.db = db;
next();
});
// app.use('/test', test);
// app.use('/ships', ships);
// app.use('/fields', fields);
// Initialise Keystone with your project's configuration.
// See http://keystonejs.com/guide/config for available options
// and documentation.
keystone.init({
'name': 'jsgrid-keystone',
'brand': 'jsgrid-keystone',
'less': 'public',
'static': 'public/image',
'favicon': 'public/favicon.ico',
'views': 'templates/views',
'view engine': 'jade',
'auto update': true,
'session': true,
'auth': true,
'user model': 'User',
});
// Load your project's Models
keystone.import('models');
// Setup common locals for your templates. The following are required for the
// bundled templates and layouts. Any runtime locals (that should be set uniquely
// for each request) should be added to ./routes/middleware.js
keystone.set('locals', {
_: require('lodash'),
env: keystone.get('env'),
utils: keystone.utils,
editable: keystone.content.editable,
});
// Load your project's Routes
keystone.set('app', app);
keystone.set('routes', require('./routes'));
// Configure the navigation bar in Keystone's Admin UI
keystone.set('nav', {
tables: ['tables', 'table_accesses'],
columns: ['columns', 'column_accesses'],
users: 'users',
access_codes: 'access_codes',
usergroups: 'usergroups',
});
keystone.set('signin redirect', function(user, req, res){
console.log('user is ', user);
if (!req.user.isAdmin) {
res.redirect('/');
}else{
res.redirect('/keystone');
};
});
// Start Keystone to connect to your database and initialise the web server
keystone.start();