Skip to content

Commit 2255e3e

Browse files
committed
PORT is now dynamic
1 parent 60c42e1 commit 2255e3e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

app/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ const md5 = require('md5');
44
const path = require('path');
55
const socketio = require('socket.io');
66

7+
const DEFAULT_PORT = 3008;
8+
79
const {
8-
PORT = 3008,
10+
PORT = DEFAULT_PORT,
911
NODE_ENV = 'production'
1012
} = process.env;
1113

@@ -28,7 +30,8 @@ const server = http.createServer((req, res) => {
2830
fs.readFile(filePath, 'utf8', (err, data) => {
2931
if (err) return showError();
3032
res.writeHead(200, { 'Content-Type': contentType });
31-
res.end(data, 'utf-8');
33+
const content = data.replace(DEFAULT_PORT, PORT);
34+
res.end(content, 'utf-8');
3235
});
3336
} else {
3437
showError();

public/reloader.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
const [a, b] = window.location.origin.split(':');
2-
const origin = [a, b, 3008].join(':');
1+
const _origin = window.location.port
2+
? window.location.origin.replace(`:${window.location.port}`)
3+
: window.location.origin;
4+
const origin = `${_origin}:${3008}`;
35

46
const updateCSS = fileName => {
57
// TODO(bret): At some point, set it up to just update the CSS that it needs to...

0 commit comments

Comments
 (0)