forked from keystonejs/keystone-test-project
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathkeystone.js
65 lines (54 loc) · 2.06 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
var keystone = require('@twreporter/keystone');
var config = require('./config');
var buildSocketIO = require('@twreporter/keystone-plugin-socketio').buildSocketIO
keystone.init(config.options);
keystone.import('models');
keystone.set('locals', config.locals);
keystone.set('routes', require('./routes'));
keystone.set('nav', config.nav);
var express = require('express');
var http = require('http');
// Create keystone app
keystone.initExpressApp();
var keystoneServer = http.createServer(keystone.app);
var shutdown = require('./lib/shutdown');
const healthCheckHandler = require('./lib/healthcheck')(keystone);
keystoneServer = shutdown.addGracefulShutdownHook(keystoneServer, {
healthChecks: {
'/healthcheck': healthCheckHandler,
},
onSignal: shutdown.cleanupKeystone(keystone),
onShutdown: shutdown.logShutdownService('keystone'),
})
keystone.openDatabaseConnection(function(){
var port = keystone.get('port') || 3000
keystoneServer.listen(port, (err) => {
console.log('------------------------------------------------')
if (err) {
console.error(err) // eslint-disable-line no-console
}
console.info('KeystoneJS ready on ', port, ' port') // eslint-disable-line no-console
console.log('------------------------------------------------')
})
});
// Create socket.io server
var app = express();
var server = http.createServer(app);
buildSocketIO(server, {
allowedOrigins: process.env.NODE_ENV === 'development' ? '*' : [
'https://keystone-editor.twreporter.org',
'https://staging-keystone-editor.twreporter.org'
],
})
server = shutdown.addGracefulShutdownHook(server,{
onShutdown: shutdown.logShutdownService('socket-io')
});
const socketioPort = process.env.SOCKETIO_PORT || 3030
server.listen(socketioPort, (err) => {
console.log('------------------------------------------------')
if (err) {
console.error(err) // eslint-disable-line no-console
}
console.info('Keystone Plugin SocketIO is ready on ', socketioPort, ' port') // eslint-disable-line no-console
console.log('------------------------------------------------')
});