README
RW API microservice utility for Nodejs applications
Library to register and integrate microservices in the RW API.
Supports Koa 2.x and 1.x frameworks.
Requirements
- Nodejs v11 or greater
Install
Using NPM:
npm install --save rw-api-microservice-node
Using Yarn:
yarn add rw-api-microservice-node
Use in microservice
In the listen
callback of your Koa application, add the following code snippet:
const Koa = require('koa');
const RWAPIMicroservice = require('rw-api-microservice-node')
const app = new Koa();
app.use(RWAPIMicroservice.bootstrap({
logger: logger,
microserviceToken: '<your microservice token>',
gatewayURL: '<your gateway URL>'
}))
// Make sure you add your auth-depending routes *after* bootstraping this module
const server = app.listen(process.env.PORT, () => {
logger.info('Server started!');
});
Configuration
These are the values you'll need to provide when using this library:
- logger: a
bunyan
logger object, for logging purposes. - gatewayURL: the URL of the API as a whole, where all other services will be reachable.
- microserviceToken: JWT token to use on calls to other services.
- skipGetLoggedUser: if set to
true
, the library will not interceptauthorization
headers nor fetch and inject the associated user data. Meant to be used by the user service. - fastlyEnabled: if set to
true
, the Fastly integration will be enabled. - fastlyServiceId and fastlyAPIKey: data for the Fastly integration. See this link for details on how to get these values. These values are required if
fastlyEnabled
istrue
.