File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ const gateway = require ( './../index' )
2
+ const PORT = process . env . PORT || 8080
3
+
4
+ gateway ( {
5
+ routes : [ {
6
+ prefix : '/service' ,
7
+ target : 'http://127.0.0.1:3000' ,
8
+ hooks : {
9
+ async onRequest ( req , res ) {
10
+ // you can alter the request object here
11
+ // adding headers:
12
+ req . headers [ 'x-header' ] = 'value'
13
+ } ,
14
+ rewriteHeaders ( headers ) {
15
+ // you can alter response headers here
16
+ return headers
17
+ } ,
18
+ onResponse ( req , res , stream ) {
19
+ // you can alter the origin response and remote response here
20
+ // default implementation explained here:
21
+ // https://www.npmjs.com/package/fast-gateway#onresponse-hook-default-implementation
22
+ }
23
+ }
24
+ } ]
25
+ } ) . start ( PORT ) . then ( server => {
26
+ console . log ( `API Gateway listening on ${ PORT } port!` )
27
+ } )
You can’t perform that action at this time.
0 commit comments