Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
042caeeeb5 | |||
6ddfaffbff | |||
567507c88b | |||
35f7bdd984 | |||
602fa2b7ff | |||
b1aae3e5b9 | |||
6b381d6115 | |||
25006901d9 | |||
ee613836d1 | |||
4b53173618 | |||
46a0220273 | |||
46a6c903e1 | |||
134151eb70 | |||
ac1c3ac53d | |||
09c23d04f4 | |||
3f359cb58c | |||
a85eb48343 | |||
7c851b5ed2 | |||
bcd69059f8 | |||
acba539a6f | |||
446b4c38ea | |||
bc6d3f45f8 | |||
bd381ff23f | |||
7e5bdf8521 |
@ -26,16 +26,28 @@ mirror:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
audit:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm audit --audit-level=high
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
|
4617
package-lock.json
generated
4617
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartssr",
|
"name": "@pushrocks/smartssr",
|
||||||
"version": "1.0.15",
|
"version": "1.0.27",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a smart server side renderer supporting shadow dom",
|
"description": "a smart server side renderer supporting shadow dom",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -10,23 +10,23 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild --web)",
|
"build": "(tsbuild --web)",
|
||||||
"format": "(gitzone format)"
|
"serve": "tsrun scripts/serve.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.24",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tstest": "^1.0.43",
|
"@gitzone/tstest": "^1.0.54",
|
||||||
"@pushrocks/smartserve": "^1.1.41",
|
"@pushrocks/smartserve": "^1.1.41",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"@types/node": "^14.0.27",
|
"@types/node": "^15.3.0",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@pushrocks/smartdelay": "^2.0.10",
|
||||||
"@pushrocks/smartfile": "^7.0.12",
|
"@pushrocks/smartfile": "^8.0.10",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.1.5",
|
||||||
"@pushrocks/smartpuppeteer": "^1.0.15",
|
"@pushrocks/smartpuppeteer": "^1.0.21",
|
||||||
"@pushrocks/smarttime": "^3.0.24"
|
"@pushrocks/smarttime": "^3.0.38"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
@ -14,9 +14,7 @@ tap.test('should start the smartssr instance', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should render central.eu', async (tools) => {
|
tap.test('should render central.eu', async (tools) => {
|
||||||
await testSSRInstance.renderPage(
|
await testSSRInstance.renderPage('https://lossless.com');
|
||||||
'https://central.eu/article/5e76873b9cf69b7bf6bc78bc/Introducing%3A%20central.eu'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.skip.test('should render lossless.com', async () => {
|
tap.skip.test('should render lossless.com', async () => {
|
||||||
@ -25,6 +23,7 @@ tap.skip.test('should render lossless.com', async () => {
|
|||||||
|
|
||||||
tap.skip.test('should render https://lossless.gmbh', async () => {
|
tap.skip.test('should render https://lossless.gmbh', async () => {
|
||||||
const renderedPage = await testSSRInstance.renderPage('https://lossless.gmbh');
|
const renderedPage = await testSSRInstance.renderPage('https://lossless.gmbh');
|
||||||
|
console.log(renderedPage);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should stop the smartssr instance', async () => {
|
tap.test('should stop the smartssr instance', async () => {
|
||||||
|
@ -11,7 +11,7 @@ export interface ISmartSSROptions {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class SmartSSR {
|
export class SmartSSR {
|
||||||
public browser: plugins.smartpuppeteer.puppeteer.Browser;
|
public browser: plugins.smartpuppeteer.IncognitoBrowser;
|
||||||
public options: ISmartSSROptions;
|
public options: ISmartSSROptions;
|
||||||
|
|
||||||
constructor(optionsArg?: ISmartSSROptions) {
|
constructor(optionsArg?: ISmartSSROptions) {
|
||||||
@ -24,12 +24,13 @@ export class SmartSSR {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async start() {
|
public async start() {
|
||||||
this.browser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance();
|
this.browser = new plugins.smartpuppeteer.IncognitoBrowser();
|
||||||
|
await this.browser.start();
|
||||||
}
|
}
|
||||||
public async stop() {
|
public async stop() {
|
||||||
if (this.browser) {
|
if (this.browser) {
|
||||||
await plugins.smartdelay.delayFor(3000);
|
await plugins.smartdelay.delayFor(3000);
|
||||||
await this.browser.close();
|
await this.browser.stop();
|
||||||
this.browser = null;
|
this.browser = null;
|
||||||
} else {
|
} else {
|
||||||
console.log('browser was not in started mode');
|
console.log('browser was not in started mode');
|
||||||
@ -40,8 +41,19 @@ export class SmartSSR {
|
|||||||
const overallTimeMeasurement = new plugins.smarttime.HrtMeasurement();
|
const overallTimeMeasurement = new plugins.smarttime.HrtMeasurement();
|
||||||
overallTimeMeasurement.start();
|
overallTimeMeasurement.start();
|
||||||
const resultDeferred = plugins.smartpromise.defer<string>();
|
const resultDeferred = plugins.smartpromise.defer<string>();
|
||||||
const context = await this.browser.createIncognitoBrowserContext();
|
const context = await this.browser.getNewIncognitoContext();
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
|
|
||||||
|
// lets protext against left open tabs
|
||||||
|
plugins.smartdelay.delayFor(30000).then(() => {
|
||||||
|
if (!page.isClosed) {
|
||||||
|
page.close();
|
||||||
|
context.close();
|
||||||
|
throw new Error(`failed to render ${urlArg}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
page.on('console', (msg) => {
|
page.on('console', (msg) => {
|
||||||
console.log(`${urlArg}: ${msg.text()}`);
|
console.log(`${urlArg}: ${msg.text()}`);
|
||||||
});
|
});
|
||||||
@ -50,6 +62,7 @@ export class SmartSSR {
|
|||||||
renderTimeMeasurement.start();
|
renderTimeMeasurement.start();
|
||||||
await page.goto(urlArg, {
|
await page.goto(urlArg, {
|
||||||
waitUntil: 'networkidle2',
|
waitUntil: 'networkidle2',
|
||||||
|
timeout: 30000,
|
||||||
});
|
});
|
||||||
|
|
||||||
let screenshotBuffer: Buffer;
|
let screenshotBuffer: Buffer;
|
||||||
@ -65,12 +78,12 @@ export class SmartSSR {
|
|||||||
const renderedPageString = pageContent;
|
const renderedPageString = pageContent;
|
||||||
resultDeferred.resolve(renderedPageString);
|
resultDeferred.resolve(renderedPageString);
|
||||||
|
|
||||||
|
|
||||||
const result = await resultDeferred.promise;
|
const result = await resultDeferred.promise;
|
||||||
renderTimeMeasurement.stop();
|
renderTimeMeasurement.stop();
|
||||||
|
|
||||||
// lets clean up async
|
// lets clean up async
|
||||||
context.close();
|
await page.close();
|
||||||
|
await context.close();
|
||||||
|
|
||||||
overallTimeMeasurement.stop();
|
overallTimeMeasurement.stop();
|
||||||
console.log(
|
console.log(
|
||||||
|
@ -39,18 +39,38 @@ export function serializeFunction(rootNode) {
|
|||||||
const nodeUUID = uuidv4();
|
const nodeUUID = uuidv4();
|
||||||
|
|
||||||
nodeArg.classList.add(nodeUUID);
|
nodeArg.classList.add(nodeUUID);
|
||||||
|
|
||||||
|
// find all slots
|
||||||
const slots = nodeArg.shadowRoot.querySelectorAll('slot');
|
const slots = nodeArg.shadowRoot.querySelectorAll('slot');
|
||||||
|
|
||||||
// handle slot element
|
// handle slot element
|
||||||
|
const slotsForMove: HTMLSlotElement[] = [];
|
||||||
slots.forEach((slot) => {
|
slots.forEach((slot) => {
|
||||||
nodeArg.childNodes.forEach((lightNode) => slot.parentNode.insertBefore(lightNode, slot));
|
slotsForMove.push(slot);
|
||||||
slot.parentNode.removeChild(slot);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (const slot of slotsForMove) {
|
||||||
|
const slottedLightNodesForMove = [];
|
||||||
|
slot.assignedNodes().forEach((lightNode) => slottedLightNodesForMove.push(lightNode));
|
||||||
|
slottedLightNodesForMove.forEach((lightNode) =>
|
||||||
|
slot.parentNode.insertBefore(lightNode, slot)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// lets modify the css
|
// lets modify the css
|
||||||
const childNodes = nodeArg.shadowRoot.childNodes;
|
const childNodes = nodeArg.shadowRoot.childNodes;
|
||||||
// tslint:disable-next-line: prefer-for-of
|
// tslint:disable-next-line: prefer-for-of
|
||||||
const noteForAppending: HTMLElement[] = [];
|
const noteForAppending: HTMLElement[] = [];
|
||||||
|
|
||||||
|
// lets care about static css first
|
||||||
|
if ((nodeArg.constructor as any).styles && (nodeArg.constructor as any).styles instanceof Array) {
|
||||||
|
for (const objectArg of (nodeArg.constructor as any).styles) {
|
||||||
|
const styleTag = document.createElement('style');
|
||||||
|
styleTag.textContent = prependCss(nodeUUID, objectArg.cssText);
|
||||||
|
noteForAppending.push(styleTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
childNodes.forEach((childNode) => {
|
childNodes.forEach((childNode) => {
|
||||||
if (childNode instanceof HTMLElement) {
|
if (childNode instanceof HTMLElement) {
|
||||||
if (childNode.tagName === 'STYLE') {
|
if (childNode.tagName === 'STYLE') {
|
||||||
@ -61,6 +81,9 @@ export function serializeFunction(rootNode) {
|
|||||||
noteForAppending.push(childNode);
|
noteForAppending.push(childNode);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
while (nodeArg.firstChild) {
|
||||||
|
nodeArg.removeChild(nodeArg.firstChild);
|
||||||
|
}
|
||||||
noteForAppending.forEach((childNode) => {
|
noteForAppending.forEach((childNode) => {
|
||||||
nodeArg.append(childNode);
|
nodeArg.append(childNode);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user