fusion-plugin-http-handler

Allows integration of an existing http handler into the fusion request lifecycle

Usage no npm install needed!

<script type="module">
  import fusionPluginHttpHandler from 'https://cdn.skypack.dev/fusion-plugin-http-handler';
</script>

README

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});
}