-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
157 lines (137 loc) · 3.49 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const platform = require('connect-platform');
let exposePanel = true;
let port = 4000;
if( process.env.CONNECT_PORT ) {
port = process.env.CONNECT_PORT;
}
if(
process.env.CONNECT_PANEL_HIDE &&
process.env.CONNECT_PANEL_HIDE.toLowerCase() === 'true'
) {
exposePanel = false;
}
//
// lets configure the platform with some presets.
//
platform
.configure({
//
// set the root directory to current directory.
//
root: __dirname,
//
// run it by default on port 4000. you can also change this value
// from within the panel.
//
port: port,
//
// lets expose the panel to be able to access it.
//
panel: {
expose: exposePanel
},
//
// loading some basic platform modules.
//
nodes: {
module: [
//
// this one is the bindings for the panel, and without it the panel
// would not work properly.
//
'connect-platform/platform/bind/panel',
//
// this one has some basic utility nodes in it that will come in handy.
//
'connect-platform/platform/bind/utils',
//
// this one is the stuff generated using the panel, so we obviously need
// to load them as well.
//
'panel-generated',
]
}
});
//
// lets do some configuration from environment.
// these configurations can be overriden via the platform.
//
//
// lets configure the remote shell.
//
platform.configure({
'remote-shell': {
enabled: (process.env.CONNECT_REMOTE_SHELL_ENABLED?
process.env.CONNECT_REMOTE_SHELL_ENABLED.toLowerCase()=='true':false),
path: process.env.CONNECT_REMOTE_SHELL_PATH || undefined,
}
});
//
// now lets try to load the configuration set by the panel.
//
try {
let panelconf = require('./panel-generated/platform-config');
platform.configure(panelconf);
} catch(err) {}
//
// and run the configuration script set by the panel.
//
try {
require('./panel-generated/platform-config.script');
} catch(err) {}
//
// and in case we are running in production environment, lets
// also load the production config overrides.
//
try {
if (process.env.CONNECT_PRODUCTION_MODE && process.env.CONNECT_PRODUCTION_MODE.toLocaleLowerCase() === 'true') {
let prodconf = require('./panel-generated/platform-config.prod');
platform.configure(prodconf);
}
} catch(err) {
console.error(err);
}
try {
if (process.env.CONNECT_ENABLE_SOCKET && process.env.CONNECT_ENABLE_SOCKET.toLocaleLowerCase() === 'true') {
console.info('Enabling sockets');
platform.configure({
enable_sockets: true
});
}
} catch(err) {
console.error(err);
}
//
// set a secret for panel if dictated by the environment variables.
//
if (process.env.CONNECT_PANEL_SECRET)
platform.configure({
panel: {
secret: process.env.CONNECT_PANEL_SECRET
}
});
//
// also if the instance is given a name by environment variables, lets
// set it too.
//
if (process.env.CONNECT_PROJECT_NAME)
platform.configure({
name: process.env.CONNECT_PROJECT_NAME
});
//
// in some environments we would need the instance to go to sleep after
// some time of inactivity.
//
if (process.env.CONNECT_INSTANCE_AUTO_SLEEP)
platform.configure({
instance_auto_sleep: process.env.CONNECT_INSTANCE_AUTO_SLEEP
});
// platform.autoparseFromEnvironmentVars();
//
// finally, start the platform.
//
platform.start()
.then(server => {
console.log(`running on http://${server.address().address}` +
`:${server.address().port}`);
});