hydris
v1.3.0
Published
Generic node service to handle SSR for SPA made with any kind of frontend framework
Downloads
18
Readme
hydris
Generic node service to handle SSR for SPA made with any kind of frontend framework. It uses puppeteer under the hood and it requires Chrome to be installed on your client.
Usage
As node service
import { scrape } from 'hydris';
(async function() {
const html = await scrape('https://dreipol.ch', '.main-footer--contacts>.main-footer--link', {
launchOptions: {
// options that will be passed to puppeteer.launch
defaultViewport: { width: 1024, height: 768 },
}
});
console.log(html); // +41 43 322 06 44 (node innerHTML included javascript generated markup)
}());
As Proxy Server
You can use hydris as a proxy server to render your javascript contents as string
import { server } from 'hydris';
import { cpus } from 'os';
import cluster from 'cluster';
if (cluster.isMaster) {
for (let i = 0; i < cpus().length; i++) {
cluster.fork();
}
} else {
// server running on 0.0.0.0:3000
server.start({
port: 3000,
launchOptions: {
// options that will be passed to puppeteer.launch
defaultViewport: { width: 1024, height: 768 },
}
});
}
// 0.0.0.0:3000?url=https://dreipol.ch&node=.main-footer--contacts>.main-footer--link
// +41 43 322 06 44
Via CLI
You can use hydris also via cli
npm i hydris -g
hydris --url https://www.dreipol.ch --node ".main-footer--contacts>.main-footer--link"
+41 43 322 06 44