From d5725c9d17a766e1610f019958b58429df51d8a4 Mon Sep 17 00:00:00 2001 From: jorgeucano Date: Wed, 15 Jan 2020 18:46:15 -0300 Subject: [PATCH 1/2] feat(puppeteerrenderplugin): add support for hostURL --- scully.config.js | 2 +- scully/renderPlugins/puppeteerRenderPlugin.ts | 8 +++++--- scully/utils/config.ts | 8 +++++++- scully/utils/interfacesandenums.ts | 1 + 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/scully.config.js b/scully.config.js index ff60e7463..8d30a4ab2 100644 --- a/scully.config.js +++ b/scully.config.js @@ -8,7 +8,7 @@ exports.config = { projectRoot: './projects/sampleBlog/src/app', /** outDir is where the static distribution files end up */ outDir: './dist/static', - + hostUrl: 'http://localhost:5000', routes: { '/demo/:id': { type: 'extra', diff --git a/scully/renderPlugins/puppeteerRenderPlugin.ts b/scully/renderPlugins/puppeteerRenderPlugin.ts index 5685553fe..147e8111d 100644 --- a/scully/renderPlugins/puppeteerRenderPlugin.ts +++ b/scully/renderPlugins/puppeteerRenderPlugin.ts @@ -9,8 +9,10 @@ import {logError, yellow} from '../utils/log'; import {launchedBrowser} from './launchedBrowser'; export const puppeteerRender = async (route: HandledRoute): Promise => { - const {version} = JSON.parse(readFileSync(join(__dirname, '../package.json')).toString()) || '0.0.0'; - const path = `http://localhost:${scullyConfig.appPort}${route.route}`; + // const {version} = JSON.parse(readFileSync(join('../package.json')).toString()) || '0.0.0'; + const path = scullyConfig.hostUrl === null ? + `http://localhost:${scullyConfig.appPort}${route.route}` + : `${scullyConfig.hostUrl}${route.route}`; let pageHtml: string; let browser: Browser; let page: Page; @@ -28,7 +30,7 @@ export const puppeteerRender = async (route: HandledRoute): Promise => { resolve(); }); - windowSet(page, 'scullyVersion', version); + // windowSet(page, 'scullyVersion', version); /** Inject this into the running page, runs in browser*/ await page.evaluateOnNewDocument(() => { diff --git a/scully/utils/config.ts b/scully/utils/config.ts index 6d1ede02b..8d77c110c 100644 --- a/scully/utils/config.ts +++ b/scully/utils/config.ts @@ -6,7 +6,6 @@ import {ScullyConfig} from './interfacesandenums'; import {logError, logWarn, yellow} from './log'; import {validateConfig} from './validateConfig'; import {compileConfig} from './compileConfig'; - export const angularRoot = findAngularJsonPath(); export const scullyConfig: ScullyConfig = {} as ScullyConfig; @@ -35,6 +34,11 @@ const loadIt = async () => { process.exit(15); } + if (compiledConfig.hostUrl && compiledConfig.hostUrl.endsWith('/')) { + compiledConfig.hostUrl = compiledConfig.hostUrl.substr(0, compiledConfig.hostUrl.length - 1); + } else if (compiledConfig.hostUrl === undefined) { + compiledConfig.hostUrl = null; + } // TODO: update types in interfacesandenums to force correct types in here. // tslint:disable-next-line: no-unused-expression Object.assign( @@ -46,6 +50,8 @@ const loadIt = async () => { appPort: /** 1864 */ 'herodevs'.split('').reduce((sum, token) => (sum += token.charCodeAt(0)), 1000), staticport: /** 1771 */ 'scully'.split('').reduce((sum, token) => (sum += token.charCodeAt(0)), 1000), defaultPostRenderers: [], + // tslint:disable-next-line:no-bitwise + hostUrl: compiledConfig.hostUrl } // compiledConfig ) as ScullyConfig; diff --git a/scully/utils/interfacesandenums.ts b/scully/utils/interfacesandenums.ts index d813d074d..683bbdaaf 100644 --- a/scully/utils/interfacesandenums.ts +++ b/scully/utils/interfacesandenums.ts @@ -17,6 +17,7 @@ export interface ScullyConfig { appPort: number; staticport: number; puppeteerLaunchOptions?: LaunchOptions; + hostUrl?: string; } interface RouteConfig { From 0839e8b8dcf48d64d575a275a60deef1639ebeaf Mon Sep 17 00:00:00 2001 From: jorgeucano Date: Wed, 15 Jan 2020 18:48:18 -0300 Subject: [PATCH 2/2] fix(scully.config.js): remove host url test --- scully.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scully.config.js b/scully.config.js index 8d30a4ab2..d7f9225db 100644 --- a/scully.config.js +++ b/scully.config.js @@ -8,7 +8,6 @@ exports.config = { projectRoot: './projects/sampleBlog/src/app', /** outDir is where the static distribution files end up */ outDir: './dist/static', - hostUrl: 'http://localhost:5000', routes: { '/demo/:id': { type: 'extra',