-
-
Save And93/f4c093814dbf32fe719ca464422e3771 to your computer and use it in GitHub Desktop.
Chrome Headless SSR for Old School
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require('puppeteer') | |
const express = require('express') | |
const app = express() | |
// page with angularjs application | |
const url = 'http://ng-seo.sourcelab.xyz/' | |
app.get('/', async function (req, res) { | |
const browser = await puppeteer.launch() | |
const page = await browser.newPage() | |
await page.goto(url) | |
// wait for element, make sure this element appears on router change completed | |
await page.waitForSelector('#main') | |
const html = await page.evaluate(() => new XMLSerializer().serializeToString(document.doctype) + document.documentElement.outerHTML) | |
res.send(html) | |
await browser.close() | |
}) | |
app.listen(3000, function () { | |
console.log('app listening on port 3000!') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment