Skip to content

Commit

Permalink
added choosePort to the build script to avoid port clashes
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbieh committed Oct 10, 2018
1 parent a4c1f0c commit 87748a6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ const webpackConfig = require('../config/webpack.config.js')(process.env.NODE_EN
const paths = require('../config/paths');
const { logMessage, compilerPromise } = require('./utils');

const { choosePort } = require('react-dev-utils/WebpackDevServerUtils');

const generateStaticHTML = async () => {
const nodemon = require('nodemon');
const fs = require('fs');
const puppeteer = require('puppeteer');
const port = await choosePort('localhost', 8505);

process.env.PORT = 8505;
process.env.PORT = port;

const script = nodemon({
script: `${paths.serverBuild}/server.js`,
Expand All @@ -20,7 +23,7 @@ const generateStaticHTML = async () => {
script.on('start', async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(`http://localhost:${process.env.PORT}`);
await page.goto(`http://localhost:${port}`);
const pageContent = await page.content();
fs.writeFileSync(`${paths.clientBuild}/index.html`, pageContent);
await browser.close();
Expand Down

0 comments on commit 87748a6

Please sign in to comment.