@@ -12,7 +12,10 @@ npm i fast-gateway
12
12
```
13
13
14
14
## Usage
15
- ### Gateway
15
+ Next we describe two examples proxying HTTP and Lambda downstream services.
16
+ > For simplicity of reading, both examples are separated, however a single gateway configuration supports all routes configurations.
17
+ ### HTTP Proxying
18
+ #### Gateway
16
19
``` js
17
20
const gateway = require (' fast-gateway' )
18
21
const server = gateway ({
@@ -24,14 +27,56 @@ const server = gateway({
24
27
25
28
server .start (8080 )
26
29
```
27
- ### Remote Service
30
+ #### Remote Service
28
31
``` js
29
32
const service = require (' restana' )()
30
33
service .get (' /get' , (req , res ) => res .send (' Hello World!' ))
31
34
32
35
service .start (3000 )
33
36
```
34
37
38
+ ### Lambda Proxying
39
+ #### Gateway
40
+ ``` bash
41
+ npm i http-lambda-proxy
42
+ ```
43
+ ``` js
44
+ const gateway = require (' fast-gateway' )
45
+ const server = gateway ({
46
+ routes: [{
47
+ prefix: ' /service' ,
48
+ target: ' my-lambda-serverless-api' ,
49
+ lambdaProxy: {
50
+ region: ' eu-central-1'
51
+ }
52
+ }]
53
+ })
54
+
55
+ server .start (8080 )
56
+ ```
57
+ #### Lambda Implementation
58
+ ``` js
59
+ const serverless = require (' serverless-http' )
60
+ const json = require (' serverless-json-parser' )
61
+ const query = require (' connect-query' )
62
+
63
+ const service = require (' restana' )()
64
+ service .use (query ())
65
+ service .use (json ())
66
+
67
+ // routes
68
+ service .get (' /get' , (req , res ) => {
69
+ res .send ({ msg: ' Go Serverless!' })
70
+ })
71
+ service .post (' /post' , (req , res ) => {
72
+ res .send (req .body )
73
+ })
74
+
75
+ // export handler
76
+ module .exports .handler = serverless (service)
77
+
78
+ ```
79
+
35
80
## Configuration options explained
36
81
``` js
37
82
{
@@ -285,6 +330,7 @@ This is your repo ;)
285
330
## Related projects
286
331
- middleware-if-unless (https://www.npmjs.com/package/middleware-if-unless )
287
332
- fast-proxy (https://www.npmjs.com/package/fast-proxy )
333
+ - http-lambda-proxy (https://www.npmjs.com/package/http-lambda-proxy )
288
334
- restana (https://www.npmjs.com/package/restana )
289
335
290
336
## Benchmarks
0 commit comments