|
3 | 3 | const gateway = require('./../index')
|
4 | 4 | const PORT = process.env.PORT || 8080
|
5 | 5 |
|
6 |
| -const { multipleHooks } = require('fg-multiple-hooks'); |
| 6 | +const { multipleHooks } = require('fg-multiple-hooks') |
7 | 7 |
|
8 | 8 | const hook1 = async (req, res) => {
|
9 |
| - console.log('hook1 with logic 1 called'); |
10 |
| - // res.send('hook failed here'); |
11 |
| - return false; // do not abort the request |
12 |
| -}; |
| 9 | + console.log('hook1 with logic 1 called') |
| 10 | + // res.send('hook failed here'); |
| 11 | + return false // do not abort the request |
| 12 | +} |
13 | 13 |
|
14 | 14 | const hook2 = async (req, res) => {
|
15 |
| - console.log('hook2 with logic 2 called'); |
16 |
| - const shouldAbort = true; |
17 |
| - if (shouldAbort) { |
18 |
| - res.send('handle a rejected request here'); |
19 |
| - } |
20 |
| - return shouldAbort; |
| 15 | + console.log('hook2 with logic 2 called') |
| 16 | + const shouldAbort = true |
| 17 | + if (shouldAbort) { |
| 18 | + res.send('handle a rejected request here') |
| 19 | + } |
| 20 | + return shouldAbort |
21 | 21 | }
|
22 | 22 |
|
23 | 23 | gateway({
|
24 | 24 | routes: [{
|
25 | 25 | prefix: '/service',
|
26 | 26 | target: 'http://127.0.0.1:3000',
|
27 | 27 | hooks: {
|
28 |
| - onRequest: (req, res) => multipleHooks(req, res, hook1, hook2), // you can add as many hooks as you please |
29 |
| - onResponse (req, res, stream) { |
30 |
| - // you can alter the origin response and remote response here |
31 |
| - // default implementation explained here: |
32 |
| - // https://www.npmjs.com/package/fast-gateway#onresponse-hook-default-implementation |
33 |
| - } |
| 28 | + onRequest: (req, res) => multipleHooks(req, res, hook1, hook2), // you can add as many hooks as you please |
| 29 | + onResponse (req, res, stream) { |
| 30 | + // you can alter the origin response and remote response here |
| 31 | + // default implementation explained here: |
| 32 | + // https://www.npmjs.com/package/fast-gateway#onresponse-hook-default-implementation |
| 33 | + } |
34 | 34 | }
|
35 | 35 | }]
|
36 | 36 | }).start(PORT).then(server => {
|
|
0 commit comments