...
Code Block | ||
---|---|---|
| ||
npm linkinstall ./apiprotect-v1.0.0.tgz |
Example adding dependency to via yarn
Code Block | ||
---|---|---|
| ||
yarn add file:./apiprotect-v1.0.0.tgz |
Step 2: Add the middleware to the application
...
Code Block | ||
---|---|---|
| ||
This middleware may be added before or after any logging middleware, but it should be after body parsing middleware and before other middleware or application code. Request Flow ┌───────────────────────────────────┐ │ │ Logging Middleware │ │ └───────────────────────────────────┘ │ ┌───────────────────────────────────┐ │ │ Body LoggingParsing Middleware │ │ └───────────────────────────────────┘ │ ┌───────────────────────────────────┐ │ │ Api Protect Middleware │ │ └───────────────────────────────────┘ │ ┌───────────────────────────────────┐ │ │ Other Middleware │ │ └───────────────────────────────────┘ │ │ ▼ * OR * Request Flow ┌───────────────────────────────────┐ │ │ Body Parsing Middleware │ │ └───────────────────────────────────┘ │ │ ┌───────────────────────────────────┐ │ │ Api Protect Middleware │ │ └───────────────────────────────────┘ │ ┌───────────────────────────────────┐ │ │ Logging Middleware │ │ └───────────────────────────────────┘ │ ┌───────────────────────────────────┐ │ │ Other Middleware │ │ └───────────────────────────────────┘ │ │ ▼ |
Example using Express middleware
Code Block |
---|
// example using Express middleware const express = require('express'); const apiprotect_middleware = require('./apiprotect-express-middlware.js'); const app = express(); // Register body parsing middlware then APIProtect middlware app.use(express.json()); app.use(apiprotect_middleware()); // ClientId read from ENV: `DT_API_PROTECT_CLIENT_ID` |
Step 3: Set the Client ID
...
Example passing client_id to Express middleware
Code Block | ||
---|---|---|
| ||
// example passing client_id to Express middleware const express = require('express'); const apiprotect_middleware = require('./apiprotect-express-middlware.js'); const settings = require('settings')l const app = express(); // Register body parsing middlware then APIProtect middlware app.use(express.json()); app.use(apiprotect_middleware({"clientId": settings.clientId})); // ClientId passed as param |