Skip to content

Commit 59f853e

Browse files
committed
Change name of environment variable
1 parent 994e164 commit 59f853e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

scripts/server.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ let connections = [];
1111
// load configuration
1212
const config = Object.assign({}, process.env);
1313

14-
const http = require(parseInt(config.SSL_ENABLED) ? 'https' : 'http');
15-
const SERVER_PORT = parseInt(config.SERVER_PORT || 2048);
16-
const WEBSOCKET_PORT = parseInt(config.WEBSOCKET_PORT || 8080);
17-
const SERVER_ADDR = (config.SERVER_ADDR || '127.0.0.1').replace(/['"]+/g, '');
18-
const AUTO_ACCEPT_CONNECTION = parseInt(config.AUTO_ACCEPT_CONNECTION);
14+
const http = require(parseInt(config.SSL_ENABLED, 10) ? 'https' : 'http');
15+
const SERVER_PORT = parseInt(config.SERVER_PORT || 2048, 10);
16+
const WEBSOCKET_PORT = parseInt(config.WEBSOCKET_PORT || 8080, 10);
17+
const SERVER_ADDRESS = (config.SERVER_ADDRESS || '127.0.0.1').replace(
18+
/['"]+/g,
19+
'',
20+
);
21+
const AUTO_ACCEPT_CONNECTION = parseInt(config.AUTO_ACCEPT_CONNECTION, 10);
1922
const ALLOWED_ORIGINS = config.ALLOWED_ORIGINS
2023
? config.ALLOWED_ORIGINS.replace(/\s/g, '')
2124
.toLowerCase()
@@ -44,15 +47,14 @@ net
4447
sock.on('data', (data) => {
4548
sock.end();
4649
sock.destroy();
47-
4850
// send data to all connected clients
4951
for (let i = 0; i < connections.length; i++) {
5052
connections[i].sendUTF(data);
5153
}
5254
});
5355
sock.on('close', (data) => {});
5456
})
55-
.listen(SERVER_PORT);
57+
.listen(SERVER_PORT, SERVER_ADDRESS);
5658

5759
// create a http server
5860
const server = http.createServer(credentials, (req, res) => {
@@ -66,9 +68,9 @@ const server = http.createServer(credentials, (req, res) => {
6668
res.end(data);
6769
});
6870
});
69-
server.listen(WEBSOCKET_PORT, () => {
71+
server.listen(WEBSOCKET_PORT, SERVER_ADDRESS, () => {
7072
logger.info(
71-
new Date() + ` Server is listening ${SERVER_ADDR}:${WEBSOCKET_PORT}`,
73+
new Date() + ` Server is listening ${SERVER_ADDRESS}:${WEBSOCKET_PORT}`,
7274
);
7375
});
7476

@@ -107,7 +109,7 @@ function originIsAllowed(origin) {
107109
" var ws = new WebSocket('" +
108110
protocol +
109111
'://' +
110-
SERVER_ADDR +
112+
SERVER_ADDRESS +
111113
':' +
112114
WEBSOCKET_PORT +
113115
"', 'echo-protocol');\n" +

0 commit comments

Comments
 (0)