Skip to content

Commit a4ad076

Browse files
Rolando Santamaria MasoRolando Santamaria Maso
authored andcommitted
adding demo with basic hostnames integration
1 parent 0b943ca commit a4ad076

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

demos/basic-hostnames.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict'
2+
3+
const gateway = require('../index')
4+
const PORT = process.env.PORT || 8080
5+
const http = require('http')
6+
const restana = require('restana')
7+
8+
const hostnames2prefix = [{
9+
prefix: '/public',
10+
hostname: 'nodejs.org'
11+
}]
12+
const hostnamesHook = require('./../lib/hostnames-hook')(hostnames2prefix)
13+
14+
const app = restana()
15+
const server = http.createServer((req, res) => {
16+
hostnamesHook(req, res, () => {
17+
return app(req, res)
18+
})
19+
})
20+
21+
gateway({
22+
server: app,
23+
middlewares: [
24+
],
25+
26+
routes: [{
27+
prefix: '/public',
28+
target: 'http://localhost:3000'
29+
}]
30+
})
31+
32+
server.listen(PORT)
33+
34+
const origin = require('restana')({})
35+
origin
36+
.get('/hi', (req, res) => res.send('Hello World!'))
37+
.start(3000)

0 commit comments

Comments
 (0)