Skip to content

Commit ef1b95d

Browse files
committed
adding url rewrite demo
1 parent 5d1aa7f commit ef1b95d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

demos/url-rewrite.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict'
2+
3+
const gateway = require('../index')
4+
const PORT = process.env.PORT || 8080
5+
6+
gateway({
7+
routes: [{
8+
pathRegex: '',
9+
prefix: '/customers/:customerId',
10+
target: 'http://localhost:3000',
11+
urlRewrite: ({ params: { customerId } }) => `/users/${customerId}`
12+
}]
13+
}).start(PORT).then(server => {
14+
console.log(`API Gateway listening on ${PORT} port!`)
15+
})
16+
17+
const service = require('restana')({})
18+
service
19+
.get('/users/:id', (req, res) => res.send('Hello ' + req.params.id))
20+
.start(3000).then(() => console.log('Service listening on 3000 port!'))

0 commit comments

Comments
 (0)