1
+ /* eslint-disable prefer-regex-literals */
2
+
1
3
'use strict'
2
4
3
5
const gateway = require ( '../index' )
@@ -7,39 +9,47 @@ const PORT = process.env.PORT || 8080
7
9
gateway ( {
8
10
server : express ( ) ,
9
11
10
- middlewares : [
11
- require ( 'cors' ) ( ) ,
12
- require ( 'helmet' ) ( )
13
- ] ,
14
-
15
- routes : [ {
16
- prefix : '/public' ,
17
- target : 'http://localhost:3000' ,
18
- docs : {
19
- name : 'Public Service' ,
20
- endpoint : 'swagger.json' ,
21
- type : 'swagger'
12
+ middlewares : [ require ( 'cors' ) ( ) , require ( 'helmet' ) ( ) ] ,
13
+
14
+ routes : [
15
+ {
16
+ prefix : new RegExp ( '/public/.*' ) , // Express.js v5 requires a RegExp object
17
+ // prefix: '/public', // Compatible with Express.js v4,
18
+
19
+ urlRewrite : ( req ) => req . url . replace ( '/public' , '' ) ,
20
+ target : 'http://localhost:3000' ,
21
+ docs : {
22
+ name : 'Public Service' ,
23
+ endpoint : 'swagger.json' ,
24
+ type : 'swagger'
25
+ }
26
+ } ,
27
+ {
28
+ prefix : new RegExp ( '/admin/.*' ) , // Express.js v5 requires a RegExp object
29
+ // prefix: '/admin', // Compatible with Express.js v4,
30
+ target : 'http://localhost:3001' ,
31
+ middlewares : [
32
+ /*
33
+ require('express-jwt').expressjwt({
34
+ secret: 'shhhhhhared-secret',
35
+ algorithms: ['HS256'],
36
+ }),
37
+ */
38
+ ]
22
39
}
23
- } , {
24
- prefix : '/admin' ,
25
- target : 'http://localhost:3001' ,
26
- middlewares : [
27
- require ( 'express-jwt' ) ( {
28
- secret : 'shhhhhhared-secret' ,
29
- algorithms : [ 'HS256' ]
30
- } )
31
- ]
32
- } ]
40
+ ]
33
41
} ) . listen ( PORT , ( ) => {
34
42
console . log ( `API Gateway listening on ${ PORT } port!` )
35
43
} )
36
44
37
45
const service1 = require ( 'restana' ) ( { } )
38
46
service1
39
47
. get ( '/hi' , ( req , res ) => res . send ( 'Hello World!' ) )
40
- . start ( 3000 ) . then ( ( ) => console . log ( 'Public service listening on 3000 port!' ) )
48
+ . start ( 3000 )
49
+ . then ( ( ) => console . log ( 'Public service listening on 3000 port!' ) )
41
50
42
51
const service2 = require ( 'restana' ) ( { } )
43
52
service2
44
- . get ( '/users' , ( req , res ) => res . send ( [ ] ) )
45
- . start ( 3001 ) . then ( ( ) => console . log ( 'Admin service listening on 3001 port!' ) )
53
+ . get ( '/admin/users' , ( req , res ) => res . send ( [ ] ) )
54
+ . start ( 3001 )
55
+ . then ( ( ) => console . log ( 'Admin service listening on 3001 port!' ) )
0 commit comments