mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-07 13:22:26 +02:00
fix: live reload port fallback if port is used (#899)
* Move start reload server into separate module * Find an unused port when starting the live reload server * Move findUnusedPort into module * Add tests for findUnusedPort module * Refactor findUnusedPort * Move starting of servers into separate module and add tests * Remove unused constants.js * Zap extra line breaks * Add tests for liveReloadServer * Rename serverController to start * Move start into lib/server * Add portfinder package * Replace findUnusedPort with portfinder * nits
This commit is contained in:
parent
c4740f7af2
commit
bbef20d345
10 changed files with 291 additions and 84 deletions
|
@ -13,7 +13,7 @@ const Head = require('./Head.js');
|
|||
|
||||
const Footer = require(`${process.cwd()}/core/Footer.js`);
|
||||
const translation = require('../server/translation.js');
|
||||
const constants = require('./constants');
|
||||
const liveReloadServer = require('../server/liveReloadServer.js');
|
||||
const {idx} = require('./utils.js');
|
||||
|
||||
const CWD = process.cwd();
|
||||
|
@ -36,6 +36,8 @@ class Site extends React.Component {
|
|||
(this.props.url || 'index.html');
|
||||
let docsVersion = this.props.version;
|
||||
|
||||
const liveReloadScriptUrl = liveReloadServer.getReloadScriptUrl();
|
||||
|
||||
if (!docsVersion && fs.existsSync(`${CWD}/versions.json`)) {
|
||||
const latestVersion = require(`${CWD}/versions.json`)[0];
|
||||
docsVersion = latestVersion;
|
||||
|
@ -147,13 +149,8 @@ class Site extends React.Component {
|
|||
/>
|
||||
))}
|
||||
|
||||
{process.env.NODE_ENV === 'development' && (
|
||||
<script
|
||||
src={`http://localhost:${
|
||||
constants.LIVE_RELOAD_PORT
|
||||
}/livereload.js`}
|
||||
/>
|
||||
)}
|
||||
{process.env.NODE_ENV === 'development' &&
|
||||
liveReloadScriptUrl && <script src={liveReloadScriptUrl} />}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue