Skip to content

Commit 68c5b59

Browse files
committed
adding lambda proxying example
1 parent 1c20bbd commit 68c5b59

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ npm i fast-gateway
1212
```
1313

1414
## 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
1619
```js
1720
const gateway = require('fast-gateway')
1821
const server = gateway({
@@ -24,14 +27,56 @@ const server = gateway({
2427

2528
server.start(8080)
2629
```
27-
### Remote Service
30+
#### Remote Service
2831
```js
2932
const service = require('restana')()
3033
service.get('/get', (req, res) => res.send('Hello World!'))
3134

3235
service.start(3000)
3336
```
3437

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+
3580
## Configuration options explained
3681
```js
3782
{
@@ -285,6 +330,7 @@ This is your repo ;)
285330
## Related projects
286331
- middleware-if-unless (https://www.npmjs.com/package/middleware-if-unless)
287332
- fast-proxy (https://www.npmjs.com/package/fast-proxy)
333+
- http-lambda-proxy (https://www.npmjs.com/package/http-lambda-proxy)
288334
- restana (https://www.npmjs.com/package/restana)
289335

290336
## Benchmarks

0 commit comments

Comments
 (0)