Skip to content

Commit 8711475

Browse files
committed
adding express server example
1 parent eb7ffbe commit 8711475

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

demos/basic-express.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const gateway = require('../index')
2+
const express = require('express')
3+
const PORT = process.env.PORT || 8080
4+
5+
gateway({
6+
server: express(),
7+
8+
middlewares: [
9+
require('cors')(),
10+
require('helmet')()
11+
],
12+
13+
routes: [{
14+
prefix: '/public',
15+
target: 'http://localhost:3000',
16+
docs: {
17+
name: 'Public Service',
18+
endpoint: 'swagger.json',
19+
type: 'swagger'
20+
}
21+
}, {
22+
prefix: '/admin',
23+
target: 'http://localhost:3001',
24+
middlewares: [
25+
require('express-jwt')({
26+
secret: 'shhhhhhared-secret'
27+
})
28+
]
29+
}]
30+
}).listen(PORT, () => {
31+
console.log(`API Gateway listening on ${PORT} port!`)
32+
})
33+
34+
const service1 = require('restana')({})
35+
service1
36+
.get('/hi', (req, res) => res.send('Hello World!'))
37+
.start(3000).then(() => console.log('Public service listening on 3000 port!'))
38+
39+
const service2 = require('restana')({})
40+
service2
41+
.get('/users', (req, res) => res.send([]))
42+
.start(3001).then(() => console.log('Admin service listening on 3001 port!'))

0 commit comments

Comments
 (0)