File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
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!' ) )
You can’t perform that action at this time.
0 commit comments