Skip to content

Commit c2f6c5e

Browse files
authored
Merge pull request #1 from RedTurtle/customizable
Customizable
2 parents 4097782 + 4e6c749 commit c2f6c5e

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
import jwtDecode from 'jwt-decode';
22

33
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+
416
const defaults = {
517
rejectanonymousSettings: {
618
userHeaderName: 'REMOTE_USER',
7-
loginUrl: '/login',
8-
excludeUrls: /^\/static|^\/login/,
19+
loginUrl,
20+
excludeUrls: new RegExp(excludeUrls),
921
},
1022
};
1123
config.settings = {
1224
...config.settings,
1325
...defaults,
1426
};
15-
if (__SERVER__) {
27+
28+
if (__SERVER__ && enabled) {
1629
const express = require('express');
1730
const middleware = express.Router();
1831
const settings = config.settings.rejectanonymousSettings;

0 commit comments

Comments
 (0)