ragu-framework / ragu-client-node

A client node for Ragu Server

Repository from Github https://github.comragu-framework/ragu-client-nodeRepository from Github https://github.comragu-framework/ragu-client-node

Ragu Client Node

Ragu Coverage Status License: MIT npm version PRs Welcome

A client for Ragu Server

You may need to fetch you micro-frontends at the server-side. This client is make for it!

Installation

$ npm install ragu-client-node

Usage

import RaguClient from 'ragu-client-node';

const client = new RaguClient();
const component = await client.fetchComponent('https://a-squad-ragu-server.organization.com/components/hello-world');

component.stylesheets(); // <style src="https://a-squad-ragu-server.organization.com/assets/hello-world.css"> 

component.html(); // html-content-from-server

component.toRaguDOM(); // <ragu-component src="https://a-squad-ragu-server.organization.com/components/hello-world">...html-content-from-server</ragu-component>

Fetch API

To be isomorphic friendly and dependency-free, Ragu Client Node uses fetch API. As node does not implement fetch API you will need a polyfill, such as cross-fetch and abort-controller.

$ npm install cross-fetch abort-controller

Registering polyfill:

require('cross-fetch/polyfill');
require('abort-controller/polyfill');

Ragu Node Client + Axios

If you already use axios as HTTP client you could use the ragu axios client.

import {RaguClient} from "ragu-node-client";
import {AxiosRequestAdapter} from "ragu-node-client/adapters/axios";

const client = new RaguClient({
  requestAdapter: new AxiosRequestAdapter()
});

Timout

You can specify a request timeout. The default is 5000ms. When a timeout occurs the fetchComponent promise will be reject with a new Error('Timeout') error.

const client = new RaguClient({
  timeout: 1000
});

About

A client node for Ragu Server

License:MIT License


Languages

Language:TypeScript 97.2%Language:JavaScript 2.8%