Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

fusionjs/fusion-plugin-http-handler

Repository files navigation

fusion-plugin-http-handler

Build status

Provides a way to hook http handlers into the fusion request lifecycle.


Table of contents


Installation

yarn add fusion-plugin-http-handler

Usage

import HttpHandlerPlugin, {HttpHandlerToken} from 'fusion-plugin-http-handler';
import App from 'fusion-react';
import express from 'express';

const expressApp = __NODE__ && express();
if (__NODE__) {
  expressApp.get('/test', (req, res) => {
    res.end('OK');
  });
}

export default function main() {
  const app = new App(<div>Hello world</div>);
  if (__NODE__) {
    app.register(HttpHandlerPlugin);
    app.register(HttpHandlerToken, expressApp);
  }
  return app;
}

Configuration

You can configure whether to run the middleware before or after await next. The default is running after await next.

import {HttpHandlerConfigToken} from 'fusion-plugin-http-handler';

// Configure to run before await next
if (__NODE__) {
  app.register(HttpHandlerConfigToken, {defer: false});
}