/
keystone.js
105 lines (82 loc) · 3.07 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
100
101
102
103
104
// Simulate config options from your production environment by
// customising the .env file in your project's root folder.
require('dotenv').load();
// Require keystone
var keystone = require('keystone');
var handlebars = require('express-handlebars');
var fs = require('fs');
// Initialise Keystone with your project's configuration.
// See http://keystonejs.com/guide/config for available options
// and documentation.
keystone.init({
//'name': 'connextcms-temp',
'name': 'keystone4',
'brand': 'ConnextCMS',
'less': 'public',
'static': 'public',
'favicon': 'public/favicon.ico',
'views': 'templates/views',
'view engine': 'hbs',
'port': 3000,
'custom engine': handlebars.create({
layoutsDir: 'templates/views/layouts',
partialsDir: 'templates/views/partials',
defaultLayout: 'default',
helpers: new require('./templates/views/helpers')(),
extname: '.hbs'
}).engine,
'auto update': true,
'session': true,
'auth': true,
'user model': 'User',
'file limit': '50MB',
'mongo': 'mongodb://172.17.0.1:3500/connextcms'
});
// 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('underscore'),
env: keystone.get('env'),
utils: keystone.utils,
editable: keystone.content.editable
});
// Load your project's Routes
keystone.set('routes', require('./routes'));
// Configure the navigation bar in Keystone's Admin UI
keystone.set('nav', {
'posts': ['posts', 'post-categories'],
'galleries': 'galleries',
'enquiries': 'enquiries',
'users': 'users'
});
//Add User GUIDs to the arrays below to make that user an Admin or Superuser.
//Only superusers can change other users passwords. They can also access the Keystone Admin UI.
//Admins can access the API and only the ConnextCMS Dashboard.
//keystone.set('superusers', ['57c88289144da4ea0dc979db']);
//keystone.set('admins', ['57c88289144da4ea0dc979db']);
//This function reads in the publicsettings.json file and sets the list of admins and superusers.
fs.readFile('public/js/publicsettings.json', 'utf8', function(err, data) {
//debugger;
if(err) {
console.log('Error in keystone.js while trying to read publicsettings.json file.');
console.log(err);
} else {
var publicSettings = JSON.parse(data);
if(typeof(publicSettings.superUsers) == "string") {
keystone.set('superusers', [publicSettings.superUsers]);
} else {
keystone.set('superusers', publicSettings.superUsers);
}
if(typeof(publicSettings.adminUsers) == "string") {
keystone.set('admins', [publicSettings.adminUsers]);
} else {
keystone.set('admins', publicSettings.adminUsers);
}
// Start Keystone to connect to your database and initialise the web server
// Need to be inside the readFile function handler.
keystone.start();
}
});