A Feathers forward service adapter. Supports only rest
provider for now.
$ npm install --save feathers-forward
Configure Feathers application to forward all unknown services to remote server.
Options:
uri
(required) - Uri to remote serverendpoint
- Type of endpoint, for now supportfeathers
(not specified ===feathers
) and everything else is default behaviour of request parsingreqHeaders
- Headers to forward from REST req object (case sensitive)resHeaders
- Headers to be added to REST res object from forwarded response (case sensitive)
Here's a example of configuration.
const compress = require('compression');
const helmet = require('helmet');
const cors = require('cors');
const feathers = require('@feathersjs/feathers');
const configuration = require('@feathersjs/configuration');
const express = require('@feathersjs/express');
const forwardMiddleware = require('feathers-forward').middleware;
const forwardConfigure = require('feathers-forward').configure;
const middleware = require('./middleware');
const services = require('./services');
const app = express(feathers());
// Load app configuration
app.configure(configuration());
// Enable security, CORS, compression, favicon and body parsing
app.use(helmet());
app.use(cors());
app.use(compress());
app.use(express.json());
app.use(express.urlencoded({extended: true}));
// Set up Plugins and providers
app.configure(express.rest());
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware);
app.configure(forwardMiddleware); // IMPORTANT
// Set up our services (see `services/index.js`)
app.configure(services);
// Forward everything else
app.configure(forwardConfigure({ // IMPORTANT
uri: 'https://example.com',
endpoint: 'feathers',
reqHeaders: ['authorization'],
resHeaders: ['custom-header']
}));
// Configure a middleware for 404s and the error handler
app.use(express.notFound());
app.use(express.errorHandler({logger}));