@@ -42,7 +42,6 @@ service.start(3000)
42
42
// If omitted, restana is used as default HTTP framework
43
43
server,
44
44
// Optional restana library configuration (https://www.npmjs.com/package/restana#configuration)
45
- //
46
45
// Please note that if "server" is provided, this settings are ignored.
47
46
restana: {},
48
47
// Optional global middlewares in the format: (req, res, next) => next()
@@ -51,23 +50,36 @@ service.start(3000)
51
50
// Optional global value for routes "pathRegex". Default value: '/*'
52
51
pathRegex: ' /*' ,
53
52
// Optional global requests timeout value (given in milliseconds). Default value: '0' (DISABLED)
53
+ // Ignored if proxyType = 'lambda'
54
54
timeout: 0 ,
55
55
// Optional "target" value that overrides the routes "target" config value. Feature intended for testing purposes.
56
56
targetOverride: " https://yourdev.api-gateway.com" ,
57
57
58
58
// HTTP proxy
59
59
routes: [{
60
+ // Optional proxy type definition. Supported values: http, lambda
61
+ // Default value: http
62
+ proxyType: ' http'
60
63
// Optional `fast-proxy` library configuration (https://www.npmjs.com/package/fast-proxy#options)
61
64
// base parameter defined as the route target. Default value: {}
65
+ // This settings apply only when proxyType = 'http'
62
66
fastProxy: {},
67
+ // Optional `http-lambda-proxy` library configuration (https://www.npmjs.com/package/http-lambda-proxy#options)
68
+ // The 'target' parameter is extracted from route.target, default region = 'eu-central-1'
69
+ // This settings apply only when proxyType = 'lambda'
70
+ lambdaProxy: {
71
+ region: ' eu-central-1'
72
+ },
63
73
// Optional proxy handler function. Default value: (req, res, url, proxy, proxyOpts) => proxy(req, res, url, proxyOpts)
64
74
proxyHandler : () => {},
65
75
// Optional flag to indicate if target uses the HTTP2 protocol. Default value: false
76
+ // This setting apply only when proxyType = 'http'
66
77
http2: false ,
67
78
// Optional path matching regex. Default value: '/*'
68
79
// In order to disable the 'pathRegex' at all, you can use an empty string: ''
69
80
pathRegex: ' /*' ,
70
81
// Optional service requests timeout value (given in milliseconds). Default value: '0' (DISABLED)
82
+ // This setting apply only when proxyType = 'http'
71
83
timeout: 0 ,
72
84
// route prefix
73
85
prefix: ' /public' ,
@@ -79,7 +91,8 @@ service.start(3000)
79
91
},
80
92
// Optional "prefix rewrite" before request is forwarded. Default value: ''
81
93
prefixRewrite: ' ' ,
82
- // Remote HTTP server URL to forward the request
94
+ // Remote HTTP server URL to forward the request.
95
+ // If proxyType = 'lambda', the value is the name of the Lambda function, version, or alias.
83
96
target: ' http://localhost:3000' ,
84
97
// Optional HTTP methods to limit the requests proxy to certain verbs only
85
98
// Supported HTTP methods: ['GET', 'DELETE', 'PATCH', 'POST', 'PUT', 'HEAD', 'OPTIONS', 'TRACE']
@@ -99,54 +112,14 @@ service.start(3000)
99
112
// ...
100
113
}
101
114
102
- // other options allowed https://www.npmjs.com/package/fast-proxy#opts
115
+ // if proxyType= 'http', other options allowed https://www.npmjs.com/package/fast-proxy#opts
103
116
}
104
117
}]
105
118
}
106
119
```
107
- ### onResponse Hook default implementation
108
- For developers reference, next we describe how the default ` onResponse ` hook looks like:
109
- ``` js
110
- const pump = require (' pump' )
111
- const toArray = require (' stream-to-array' )
112
- const TRANSFER_ENCODING_HEADER_NAME = ' transfer-encoding'
113
-
114
- const onResponse = async (req , res , stream ) => {
115
- const chunked = stream .headers [TRANSFER_ENCODING_HEADER_NAME ]
116
- ? stream .headers [TRANSFER_ENCODING_HEADER_NAME ].endsWith (' chunked' )
117
- : false
118
-
119
- if (req .headers .connection === ' close' && chunked) {
120
- try {
121
- // remove transfer-encoding header
122
- const transferEncoding = stream .headers [TRANSFER_ENCODING_HEADER_NAME ].replace (/ (,( )? )? chunked/ , ' ' )
123
- if (transferEncoding) {
124
- res .setHeader (TRANSFER_ENCODING_HEADER_NAME , transferEncoding)
125
- } else {
126
- res .removeHeader (TRANSFER_ENCODING_HEADER_NAME )
127
- }
128
-
129
- if (! stream .headers [' content-length' ]) {
130
- // pack all pieces into 1 buffer to calculate content length
131
- const resBuffer = Buffer .concat (await toArray (stream))
132
-
133
- // add content-length header and send the merged response buffer
134
- res .setHeader (' content-length' , ' ' + Buffer .byteLength (resBuffer))
135
- res .statusCode = stream .statusCode
136
- res .end (resBuffer)
120
+ ### onResponse hooks default implementation
121
+ For developers reference, default hooks implementation are located in ` lib/default-hooks.js ` file.
137
122
138
- return
139
- }
140
- } catch (err) {
141
- res .statusCode = 500
142
- res .end (err .message )
143
- }
144
- }
145
-
146
- res .statusCode = stream .statusCode
147
- pump (stream, res)
148
- }
149
- ```
150
123
## The "* GET /services.json* " endpoint
151
124
Since version ` 1.3.5 ` the gateway exposes minimal documentation about registered services at: ` GET /services.json `
152
125
0 commit comments