-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
67 lines (61 loc) · 2.8 KB
/
index.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
/**
*
* Reldens - NPM Test
*
* ServerPlugin initialization and events.
* This is a test example file on how the server can be initialized.
*
*/
// required the module:
const { ServerManager } = require('reldens/server');
// custom plugin (if you like to implement customizations do it there):
const { ServerPlugin } = require('./theme/plugins/server-plugin');
// you can find an example of the server file in node_modules/reldens/theme/packages/server-plugin.js
// create a server instance passing the current root:
let appServer = new ServerManager({
projectRoot: __dirname, // we need to pass the server root
projectThemeName: 'custom-game-theme-test', // if the project theme is not specified then "default" will be used
jsSourceMaps: '1' === process.env.RELDENS_JS_SOURCEMAPS, // enable JS source maps to debug the client on your IDE
cssSourceMaps: '1' === process.env.RELDENS_CSS_SOURCEMAPS,
customPlugin: ServerPlugin
});
console.log('TEST - All these are TEST logs that you can remove from your index file.');
// events debug:
// appServer.events.debug = 'all'; // or any string containing multiple events keys.
// setup as you need:
appServer.events.on('reldens.serverConfigFeaturesReady', (props) => {
console.log('TEST - Events test reldens.serverConfigFeaturesReady success!');
});
// blocked admin actions test (remove to enable the admin actions):
if('1' === process.env.RELDENS_BLOCKED_ADMIN){
appServer.events.on('reldens.afterCreateAdminManager', (event) => {
console.log('DEMO - Hardcoded event to disable CRUD Administration Panel.');
let blackList = [];
for(let driverResource of event.serverManager.serverAdmin.resources){
let entityRoute = '/'+driverResource.entityPath;
blackList.push(entityRoute + event.serverManager.serverAdmin.savePath);
blackList.push(entityRoute + event.serverManager.serverAdmin.deletePath);
}
event.serverManager.serverAdmin.blackList['1'] = blackList; // block registered users
event.serverManager.serverAdmin.blackList['2'] = blackList; // block guest users
event.serverManager.serverAdmin.blackList['99'] = blackList; // block admin users
});
// custom users authentication test:
appServer.events.on('reldens.roomLoginOnAuth', (props) => {
// deny login for users the incorrect role:
if(4 === props.loginResult.user.role_id){
props.result.confirm = false;
}
});
}
// run the server!
console.log('TEST - ServerPlugin starting...');
appServer.createServers().then(() => {
console.log('TEST - CREATED APP SERVER INSTANCE!');
appServer.start().then(() => {
console.log('TEST - SERVER UP AND RUNNING!');
}).catch((err) => {
console.log('TEST - ServerPlugin error:', err);
process.exit();
});
});