From 88a1b2667302a3557d99957b3885b5569a9de9cf Mon Sep 17 00:00:00 2001 From: Sander Elias Date: Wed, 5 Feb 2020 15:18:28 +0100 Subject: [PATCH] fix(hosturl): fix hostURL so the our internal server is not started, and we are quireing (#277) dont start the internal server, and use the given one from `hostUrl` --- README.md | 2 ++ scully.sampleBlog.config.js | 1 + .../routerPlugins/traverseAppRoutesPlugin.ts | 4 +-- scully/scully.ts | 35 +++++++++++-------- scully/utils/cache.ts | 2 ++ scully/utils/defaultAction.ts | 9 +++-- 6 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 scully/utils/cache.ts diff --git a/README.md b/README.md index e7fcc2bbd..dc62889e1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Scully +[![](./assets/logos/PNG/scullyio-logo.png)]() + [![GitHub](https://img.shields.io/github/license/scullyio/scully)](https://github.com/scullyio/scully/blob/master/LICENSE) [![Gitter](https://img.shields.io/gitter/room/scullyio/community)](https://gitter.im/scullyio/community) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) diff --git a/scully.sampleBlog.config.js b/scully.sampleBlog.config.js index 00f1fe0f9..07b6ddd68 100644 --- a/scully.sampleBlog.config.js +++ b/scully.sampleBlog.config.js @@ -7,6 +7,7 @@ exports.config = { /** outDir is where the static distribution files end up */ outDir: './dist/static', // hostName: '0.0.0.0', + hostUrl: 'http://localHost:5000', extraRoutes: [''], routes: { '/demo/:id': { diff --git a/scully/routerPlugins/traverseAppRoutesPlugin.ts b/scully/routerPlugins/traverseAppRoutesPlugin.ts index be8029213..3f22323c9 100644 --- a/scully/routerPlugins/traverseAppRoutesPlugin.ts +++ b/scully/routerPlugins/traverseAppRoutesPlugin.ts @@ -42,9 +42,9 @@ ${green('When there are extraRoutes in your config, we will still try to render } // process.exit(15); const allRoutes = [...routes, ...extraRoutes]; - if (allRoutes.findIndex(r => r === '') === -1) { + if (allRoutes.findIndex(r => r.trim() === '' || r.trim() === '/') === -1) { /** make sure the root Route is always rendered. */ - allRoutes.push(''); + allRoutes.push('/'); } return allRoutes; }; diff --git a/scully/scully.ts b/scully/scully.ts index e9fd70012..15bd3c922 100644 --- a/scully/scully.ts +++ b/scully/scully.ts @@ -8,11 +8,11 @@ import {join} from 'path'; import * as yargs from 'yargs'; import './pluginManagement/systemPlugins'; import {startBackgroundServer} from './startBackgroundServer'; -import {loadConfig, scullyConfig} from './utils/config'; +import {loadConfig} from './utils/config'; import {moveDistAngular} from './utils/fsAngular'; import {httpGetJson} from './utils/httpGetJson'; import {isPortTaken} from './utils/isPortTaken'; -import {logError} from './utils/log'; +import {logError, logWarn, yellow} from './utils/log'; import {startScully} from './utils/startup'; import {waitForServerToBeAvailable} from './utils/waitForServerToBeAvailable'; import {bootServe, isBuildThere, watchMode} from './watchMode'; @@ -62,19 +62,24 @@ if (process.argv.includes('version')) { const folder = join(scullyConfig.homeFolder, scullyConfig.distFolder); /** copy in current build artifacts */ await moveDistAngular(folder, scullyConfig.outDir, {removeStaticDist, reset: false}); - - /** server ports already in use? */ const isTaken = await isPortTaken(scullyConfig.staticport); - if (!isTaken) { - startBackgroundServer(scullyConfig); - } else { - // debug only - console.log(`Background servers already running.`); - } - if (!(await waitForServerToBeAvailable().catch(e => false))) { - logError('Could not connect to server'); - process.exit(15); + if (typeof scullyConfig.hostUrl === 'string') { + logWarn(` +You are using "${yellow(scullyConfig.hostUrl)}" as server. + `); + } else { + /** server ports already in use? */ + if (!isTaken) { + startBackgroundServer(scullyConfig); + } else { + // debug only + console.log(`Background servers already running.`); + } + if (!(await waitForServerToBeAvailable().catch(e => false))) { + logError('Could not connect to server'); + process.exit(15); + } } if (watch) { watchMode( @@ -82,9 +87,9 @@ if (process.argv.includes('version')) { join(scullyConfig.homeFolder, './dist/browser') ); } else { - console.log('servers available'); + // console.log('servers available'); await startScully(); - if (!isTaken) { + if (!isTaken && typeof scullyConfig.hostUrl !== 'string') { // kill serve ports await httpGetJson(`http://${scullyConfig.hostName}:${scullyConfig.appPort}/killMe`, { suppressErrors: true, diff --git a/scully/utils/cache.ts b/scully/utils/cache.ts new file mode 100644 index 000000000..07b14c2f4 --- /dev/null +++ b/scully/utils/cache.ts @@ -0,0 +1,2 @@ +export const rawRoutesCache = new Set(); +export const flushRawRoutesCache = () => rawRoutesCache.clear(); diff --git a/scully/utils/defaultAction.ts b/scully/utils/defaultAction.ts index 85abd17b5..5a74fb7ae 100644 --- a/scully/utils/defaultAction.ts +++ b/scully/utils/defaultAction.ts @@ -12,6 +12,7 @@ import {chunk} from './chunk'; import {loadConfig} from './config'; import {log, logWarn} from './log'; import {performanceIds} from './performanceIds'; +import {rawRoutesCache} from './cache'; export const {baseFilter} = yargs .string('bf') @@ -19,22 +20,20 @@ export const {baseFilter} = yargs .default('bf', '') .describe('bf', 'provide a minimatch glob for the unhandled routes').argv; -const cache = new Set(); - console.log(baseFilter); export const generateAll = async (localBaseFilter = baseFilter) => { await loadConfig; try { let unhandledRoutes; - if (cache.size == 0) { + if (rawRoutesCache.size === 0) { log('Finding all routes in application.'); performance.mark('startTraverse'); unhandledRoutes = await traverseAppRoutes(); performance.mark('stopTraverse'); performanceIds.add('Traverse'); - unhandledRoutes.forEach(r => cache.add(r)); + unhandledRoutes.forEach(r => rawRoutesCache.add(r)); } else { - unhandledRoutes = [...cache.keys()]; + unhandledRoutes = [...rawRoutesCache.keys()]; } if (unhandledRoutes.length < 1) {