Skip to content
A flexible API to forward HTTP requests to another server
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
test
.gitignore
LICENSE
README.md
index.js
package.json
yarn.lock

README.md

relay

A flexible API to forward HTTP requests to another server

npm page

Installation

yarn add @ianwalter/relay

Usage

Express setup example:

const Relay = require('@ianwalter/relay')

// Create the Relay instance and save it to the Express app instance so that
// route handlers will be able to access it when called.
const app = express()
app.locals.relay = new Relay({ baseUrl: process.env.API_URL })

Express simple proxy example:

const Relay = require('@ianwalter/relay')

// Proxy all requests to /api/account to /api/account on the baseUrl setup in
// the example above.
app.post('/api/account', Relay.proxy())

Express advanced proxy example:

const Relay = require('@ianwalter/relay')

// Pass the addAuthHeader function into the proxy options so that the authToken
// in the user's session is passed as an Authorization header when proxying
// requests to the other server.
const addAuthHeader = req => ({
  headers: { 'Authorization': req.session.authToken }
})
app.put('/api/account', Relay.proxy(addAuthHeader))

License

Apache 2.0 with Commons Clause - See LICENSE

 

Created by Ian Walter

You can’t perform that action at this time.