3.1.0 • Published 5 years ago
@ianwalter/relay v3.1.0
relay
A flexible API to forward HTTP requests to another server
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
3.1.0
5 years ago
3.0.6
5 years ago
3.0.5
5 years ago
3.0.4
5 years ago
3.0.3
5 years ago
3.0.2
5 years ago
3.0.1
5 years ago
3.0.0
5 years ago
2.8.0
5 years ago
2.7.0
5 years ago
2.6.1
5 years ago
2.6.0
5 years ago
2.5.0
5 years ago
2.4.1
5 years ago
2.4.0
5 years ago
2.3.1
5 years ago
2.3.0
5 years ago
2.2.2
5 years ago
2.2.1
5 years ago
2.2.0
5 years ago
2.1.3
5 years ago
2.1.2
5 years ago
2.1.1
5 years ago
2.1.0
5 years ago
2.0.1
5 years ago
2.0.0
5 years ago
1.4.0
5 years ago
1.3.3
6 years ago
1.3.2
6 years ago
1.3.1
6 years ago
1.3.0
6 years ago
1.2.0
6 years ago
1.1.0
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago