Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"cuid": "^1.3.8",
"eventify": "^2.0.0",
"express": "^4.13.4",
"find-port": "^2.0.1",
"fixed-data-table-2": "^0.7.7",
"highlight.js": "^8.9.1",
"marked": "^0.3.5",
Expand Down
28 changes: 22 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import config from './webpack.dev.config.js';
import findPort from 'find-port';

const app = express(),
compiler = webpack(config),
PORT = 3001;
compiler = webpack(config);
let PORT;

app.use(webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
Expand All @@ -23,11 +24,26 @@ app.use(webpackHotMiddleware(compiler, {
heartbeat: 10 * 1000
}));

app.listen(PORT, 'localhost', err => {
if (err) {
console.error(err);
// before binding our server to a port, check each port in the given range
// to ensure it's available. Upon return, just go ahead with the first element
findPort('localhost', [3001, 9000, 9001, 9002], (ports) => {

if (ports.length === 0) {
console.error(`This is rather embarrasing : none of the given ports are available`);
return;
}

console.log(`Listening at http://localhost:${PORT}`);
// make use of the first available port returned
PORT = ports[0];
app.listen(PORT, 'localhost', err => {
if (err) {
console.error(err);
return;
}

console.log(`Listening at http://localhost:${PORT}`);
});

});