File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change 1
1
import jwtDecode from 'jwt-decode' ;
2
2
3
3
const applyConfig = ( config ) => {
4
+ const { prefixPath } = config . settings ;
5
+ const redirectUrl =
6
+ process . env . RAZZLE_REJECT_ANONYMOUS_REDIRECT_URL || '/login' ;
7
+ const enabled = process . env . RAZZLE_REJECT_ANONYMOUS || false ;
8
+
9
+ const loginUrl = prefixPath
10
+ ? `${ prefixPath } ${ redirectUrl } `
11
+ : `/${ redirectUrl } ` ;
12
+ const excludeUrls = prefixPath
13
+ ? `^\\/static|^\\${ prefixPath } \\${ redirectUrl } `
14
+ : `^\\/static|^\\${ redirectUrl } ` ;
15
+
4
16
const defaults = {
5
17
rejectanonymousSettings : {
6
18
userHeaderName : 'REMOTE_USER' ,
7
- loginUrl : '/login' ,
8
- excludeUrls : / ^ \/ s t a t i c | ^ \/ l o g i n / ,
19
+ loginUrl,
20
+ excludeUrls : new RegExp ( excludeUrls ) ,
9
21
} ,
10
22
} ;
11
23
config . settings = {
12
24
...config . settings ,
13
25
...defaults ,
14
26
} ;
15
- if ( __SERVER__ ) {
27
+
28
+ if ( __SERVER__ && enabled ) {
16
29
const express = require ( 'express' ) ;
17
30
const middleware = express . Router ( ) ;
18
31
const settings = config . settings . rejectanonymousSettings ;
You can’t perform that action at this time.
0 commit comments