-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeystone.js
105 lines (87 loc) · 2.9 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
105
require('dotenv').config();
var keystone = require('keystone'),
keystoneRestApi = require('keystone-rest-api'),
webpack = require('webpack'),
MemoryFS = require("memory-fs"),
path = require('path'),
devMiddleware = require('webpack-dev-middleware'),
hotMiddleware = require('webpack-hot-middleware'),
config = require('./webpack.config.js'),
compiler = webpack(config);
var mem_fs = new MemoryFS();
compiler.outputFileSystem = mem_fs;
console.log("Environment:" + process.env.NODE_ENV);
var isDev = process.env.NODE_ENV == 'development';
keystone.init({
'name': 'keystone-angular2-webpack-starter',
'brand': 'keystone-angular2-webpack-starter',
'static': 'src/public',
'favicon': 'src/public/favicon.ico',
'emails': 'templates/emails',
'auto update': true,
'session': true,
'auth': true,
'user model': 'User',
'cookie secret': process.env.COOKIE_SECRET || '(my secret)'
});
// Load your project's Models
keystone.import('models');
keystone.set('routes', function (app) {
if (isDev) {
app.use(devMiddleware(compiler, {
publicPath: config.output.publicPath
}));
app.use(hotMiddleware(compiler, {
log: console.log
}));
}
// Add routes with Keystone
keystoneRestApi.createRest(keystone, {
apiRoot: '/api/v1/'
});
app.get('*', function (req, res, next) {
var filename = path.join(compiler.outputPath, 'index.html');
console.log('file:' + filename);
compiler.outputFileSystem.readFile(filename, function (err, result) {
if (err) {
return next(err);
}
res.set('content-type', 'text/html');
res.send(result);
res.end();
});
});
});
// 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,
});
// Setup common locals for your emails. The following are required by Keystone's
// default email templates, you may remove them if you're using your own.
keystone.set('email locals', {
logo_src: '/img/angular.png',
logo_width: 194,
logo_height: 76,
theme: {
email_bg: '#f9f9f9',
link_color: '#2697de',
buttons: {
color: '#fff',
background_color: '#2697de',
border_color: '#1a7cb7',
},
},
});
// Load your project's email test routes
//keystone.set('email tests', require('./routes/emails'));
// Configure the navigation bar in Keystone's Admin UI
keystone.set('nav', {
users: 'users',
});
// Start Keystone to connect to your database and initialise the web server
keystone.start();