hydris

1.3.0 • Public • Published

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.

Build Status Coverage Status

NPM version NPM downloads MIT License

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

TODO

  • requests handling via process forking (see also and here)
  • persistent browser scraper to improve the performances

Package Sidebar

Install

npm i hydris

Weekly Downloads

2

Version

1.3.0

License

MIT

Unpacked Size

16.4 kB

Total Files

8

Last publish

Collaborators

  • hannahku
  • philipplaeubli
  • fabricetobler
  • thibi
  • gianlucaguarini