Provides a way to hook http handlers into the fusion request lifecycle.
yarn add fusion-plugin-http-handler
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;
}
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});
}