Skip to content

Commit 9228290

Browse files
committed
Replace BASE_PATH with PROXY_PATH
1 parent 4c0c584 commit 9228290

File tree

7 files changed

+84
-83
lines changed

7 files changed

+84
-83
lines changed

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:14.15-alpine
1+
FROM node:14.17-alpine
22

33
WORKDIR /usr/app
44

@@ -14,6 +14,8 @@ ENV BULL_PREFIX bull
1414
ENV BULL_VERSION BULLMQ
1515
ENV USER_LOGIN ''
1616
ENV USER_PASSWORD ''
17+
ENV REDIS_DB 0
18+
ENV PROXY_PATH ''
1719

1820
RUN yarn install
1921

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ see "Example with docker-compose" section for example with env parameters
3030
### Environment variables
3131
* `REDIS_HOST` - host to connect to redis (localhost by default)
3232
* `REDIS_PORT` - redis port (6379 by default)
33-
* `REDIS_DB` - redis db ('0' by default)
33+
* `REDIS_DB` - redis db to use ('0' by default)
3434
* `REDIS_USE_TLS` - enable TLS true or false (false by default)
3535
* `REDIS_PASSWORD` - password to connect to redis (no password by default)
3636
* `BULL_PREFIX` - prefix to your bull queue name (bull by default)
3737
* `BULL_VERSION` - version of bull lib to use 'BULLMQ' or 'BULL' ('BULLMQ' by default)
38-
* `BASE_PATH` - basePath for bull board, e.g. '/bull-board' ('/' by default)
39-
* `PROXY_PATH` - proxyPath for bull board, e.g. '/bull-board' ('' by default)
38+
* `PROXY_PATH` - proxyPath for bull board, e.g. https://<server_name>/my-base-path/queues [docs] ('' by default)
4039
* `USER_LOGIN` - login to restrict access to bull-board interface (disabled by default)
4140
* `USER_PASSWORD` - password to restrict access to bull-board interface (disabled by default)
4241

@@ -82,3 +81,4 @@ volumes:
8281
```
8382

8483
[bull-board]: https://github.com/vcapretz/bull-board
84+
[bull-board]: https://github.com/felixmosh/bull-board#hosting-router-on-a-sub-path

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"bull-board": "^2.0.3",
1313
"bullmq": "^1.8.4",
1414
"connect-ensure-login": "^0.1.1",
15-
"dotenv": "^8.2.0",
15+
"dotenv": "^9.0.2",
1616
"express": "^4.17.1",
1717
"express-session": "^1.17.1",
1818
"morgan": "^1.10.0",

src/config.js

+16-20
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
require('dotenv').config();
22

33
function normalizePath(pathStr) {
4-
return (pathStr || '').replace(/\/$/, '');
4+
return (pathStr || '').replace(/\/$/, '');
55
}
66

7-
const BASE_PATH = normalizePath(process.env.BASE_PATH);
8-
const PROXY_PATH = normalizePath(process.env.PROXY_PATH) + BASE_PATH;
7+
const PROXY_PATH = normalizePath(process.env.PROXY_PATH);
98

109
const config = {
11-
REDIS_PORT: process.env.REDIS_PORT || 6379,
12-
REDIS_HOST: process.env.REDIS_HOST || 'localhost',
13-
REDIS_DB: process.env.REDIS_DB || '0',
14-
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
15-
REDIS_USE_TLS: process.env.REDIS_USE_TLS,
16-
BULL_PREFIX: process.env.BULL_PREFIX || 'bull',
17-
BULL_VERSION: process.env.BULL_VERSION || 'BULLMQ',
18-
PORT: process.env.PORT || 3000,
19-
BASE_PATH: BASE_PATH,
20-
PROXY_PATH: PROXY_PATH,
21-
USER_LOGIN: process.env.USER_LOGIN,
22-
USER_PASSWORD: process.env.USER_PASSWORD,
10+
REDIS_PORT: process.env.REDIS_PORT || 6379,
11+
REDIS_HOST: process.env.REDIS_HOST || 'localhost',
12+
REDIS_DB: process.env.REDIS_DB || '0',
13+
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
14+
REDIS_USE_TLS: process.env.REDIS_USE_TLS,
15+
BULL_PREFIX: process.env.BULL_PREFIX || 'bull',
16+
BULL_VERSION: process.env.BULL_VERSION || 'BULLMQ',
17+
PORT: process.env.PORT || 3000,
18+
PROXY_PATH: PROXY_PATH,
19+
USER_LOGIN: process.env.USER_LOGIN,
20+
USER_PASSWORD: process.env.USER_PASSWORD,
2321

24-
AUTH_ENABLED: Boolean(process.env.USER_LOGIN && process.env.USER_PASSWORD),
25-
HOME_PAGE: BASE_PATH || '/',
26-
LOGIN_PAGE: `${BASE_PATH}/login`,
27-
PROXY_HOME_PAGE: PROXY_PATH || '/',
28-
PROXY_LOGIN_PAGE: `${PROXY_PATH}/login`,
22+
AUTH_ENABLED: Boolean(process.env.USER_LOGIN && process.env.USER_PASSWORD),
23+
HOME_PAGE: PROXY_PATH || '/',
24+
LOGIN_PAGE: `${PROXY_PATH}/login`,
2925
};
3026

3127
module.exports = config;

src/index.js

+26-23
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ const {authRouter} = require('./login');
1414
const config = require('./config');
1515

1616
const redisConfig = {
17-
redis: {
18-
port: config.REDIS_PORT,
19-
host: config.REDIS_HOST,
20-
db: config.REDIS_DB,
21-
...(config.REDIS_PASSWORD && {password: config.REDIS_PASSWORD}),
22-
tls: config.REDIS_USE_TLS === 'true',
23-
},
17+
redis: {
18+
port: config.REDIS_PORT,
19+
host: config.REDIS_HOST,
20+
db: config.REDIS_DB,
21+
...(config.REDIS_PASSWORD && {password: config.REDIS_PASSWORD}),
22+
tls: config.REDIS_USE_TLS === 'true',
23+
},
2424
};
2525

2626
const client = redis.createClient(redisConfig.redis);
@@ -48,25 +48,28 @@ app.set('views', __dirname + '/views');
4848
app.set('view engine', 'ejs');
4949

5050
if (app.get('env') !== 'production') {
51-
const morgan = require('morgan');
52-
app.use(morgan('combined'));
51+
const morgan = require('morgan');
52+
app.use(morgan('combined'));
5353
}
5454

5555
app.use((req, res, next) => {
56-
if (config.PROXY_PATH) req.proxyUrl = config.PROXY_PATH;
57-
next();
56+
if (config.PROXY_PATH) {
57+
req.proxyUrl = config.PROXY_PATH;
58+
}
59+
60+
next();
5861
});
5962

6063
const sessionOpts = {
61-
name: 'bull-board.sid',
62-
secret: Math.random().toString(),
63-
resave: false,
64-
saveUninitialized: false,
65-
cookie: {
66-
path: '/',
67-
httpOnly: false,
68-
secure: false
69-
}
64+
name: 'bull-board.sid',
65+
secret: Math.random().toString(),
66+
resave: false,
67+
saveUninitialized: false,
68+
cookie: {
69+
path: '/',
70+
httpOnly: false,
71+
secure: false
72+
}
7073
};
7174

7275
app.use(session(sessionOpts));
@@ -75,10 +78,10 @@ app.use(passport.session({}));
7578
app.use(bodyParser.urlencoded({extended: false}));
7679

7780
if (config.AUTH_ENABLED) {
78-
app.use(config.LOGIN_PAGE, authRouter);
79-
app.use(config.HOME_PAGE, ensureLoggedIn(config.PROXY_LOGIN_PAGE), router);
81+
app.use(config.LOGIN_PAGE, authRouter);
82+
app.use(config.HOME_PAGE, ensureLoggedIn(config.LOGIN_PAGE), router);
8083
} else {
81-
app.use(config.HOME_PAGE, router);
84+
app.use(config.HOME_PAGE, router);
8285
}
8386

8487
app.listen(config.PORT, () => {

src/login.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ const config = require('./config');
77
const authRouter = express.Router();
88

99
passport.use(new LocalStrategy(
10-
function (username, password, cb) {
11-
if (username === config.USER_LOGIN && password === config.USER_PASSWORD) {
12-
return cb(null, {user: 'bull-board'});
13-
}
10+
function (username, password, cb) {
11+
if (username === config.USER_LOGIN && password === config.USER_PASSWORD) {
12+
return cb(null, {user: 'bull-board'});
13+
}
1414

15-
return cb(null, false);
16-
})
15+
return cb(null, false);
16+
})
1717
);
1818

1919
passport.serializeUser((user, cb) => {
20-
cb(null, user);
20+
cb(null, user);
2121
});
2222

2323
passport.deserializeUser((user, cb) => {
24-
cb(null, user);
24+
cb(null, user);
2525
});
2626

2727
authRouter.route('/')
28-
.get((req, res) => {
29-
res.render('login');
30-
})
31-
.post(passport.authenticate('local', {
32-
successRedirect: config.PROXY_HOME_PAGE,
33-
failureRedirect: config.PROXY_LOGIN_PAGE,
34-
}));
28+
.get((req, res) => {
29+
res.render('login');
30+
})
31+
.post(passport.authenticate('local', {
32+
successRedirect: config.HOME_PAGE,
33+
failureRedirect: config.LOGIN_PAGE,
34+
}));
3535

3636
exports.authRouter = authRouter;

yarn.lock

+20-20
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
"@types/serve-static" "*"
3838

3939
"@types/ioredis@^4.22.2":
40-
version "4.26.2"
41-
resolved "https://registry.yarnpkg.com/@types/ioredis/-/ioredis-4.26.2.tgz#6185392fc771f758e26aa9ed99dac25f5e9a76d0"
42-
integrity sha512-Dliwq2BDTs+Wljw3ByL9nG7XxakpvepvCUI/0tHH8RLsJ2LwUoxVr+/ZnbFD4uF8Uw/k6eFSvxvbUGbV6iVldg==
40+
version "4.26.3"
41+
resolved "https://registry.yarnpkg.com/@types/ioredis/-/ioredis-4.26.3.tgz#5b660125d07214c67a5d9a0d9c678375c717d93f"
42+
integrity sha512-2YiIUTo/MCZidXXfHAIoh2DUlGEG7zYFMfz0VXzTpI5934/wBCT5a/pR24lHCKk9WQNIlYauIFxQHcAF93w1FA==
4343
dependencies:
4444
"@types/node" "*"
4545

@@ -49,9 +49,9 @@
4949
integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==
5050

5151
"@types/node@*":
52-
version "15.0.2"
53-
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.0.2.tgz#51e9c0920d1b45936ea04341aa3e2e58d339fb67"
54-
integrity sha512-p68+a+KoxpoB47015IeYZYRrdqMUcpbK8re/zpFB8Ld46LHC1lPEbp3EXgkEhAYEcPvjJF6ZO+869SQ0aH1dcA==
52+
version "15.3.0"
53+
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.3.0.tgz#d6fed7d6bc6854306da3dea1af9f874b00783e26"
54+
integrity sha512-8/bnjSZD86ZfpBsDlCIkNXIvm+h6wi9g7IqL+kmFkQ+Wvu3JrasgLElfiPgoo8V8vVfnEi0QVS12gbl94h9YsQ==
5555

5656
"@types/qs@*":
5757
version "6.9.6"
@@ -103,8 +103,8 @@ balanced-match@^1.0.0:
103103

104104
basic-auth@~2.0.1:
105105
version "2.0.1"
106-
resolved "https://registry.npm.taobao.org/basic-auth/download/basic-auth-2.0.1.tgz#b998279bf47ce38344b4f3cf916d4679bbf51e3a"
107-
integrity sha1-uZgnm/R844NEtPPPkW1Gebv1Hjo=
106+
resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-2.0.1.tgz#b998279bf47ce38344b4f3cf916d4679bbf51e3a"
107+
integrity sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==
108108
dependencies:
109109
safe-buffer "5.1.2"
110110

@@ -144,9 +144,9 @@ bull-board@^2.0.3:
144144
redis-info "^3.0.8"
145145

146146
bull@^3.13.0:
147-
version "3.22.4"
148-
resolved "https://registry.yarnpkg.com/bull/-/bull-3.22.4.tgz#1bda418d2aebdf892413d0c45d75c8ea5e0fc984"
149-
integrity sha512-CV78TuSKyDj3SuZvySTOFXqZBtHxebhctLTq2Ff9Jrn51XOaxkEDioIDzq2LIUKEhTW8l3rFK5bIWNwweY0LXQ==
147+
version "3.22.5"
148+
resolved "https://registry.yarnpkg.com/bull/-/bull-3.22.5.tgz#ab42d76ecb7d8c5faba7a6a6e1d8b0ed0cde7ff5"
149+
integrity sha512-wA5CRChiqF7bQ3/mLToFRiAKujWVBJJ07Ok368aiER8N1ail0veHwHc02I4lMMUyG9WoxHCHyrCqyPQhDGrd2w==
150150
dependencies:
151151
cron-parser "^2.13.0"
152152
debuglog "^1.0.0"
@@ -160,9 +160,9 @@ bull@^3.13.0:
160160
uuid "^8.3.0"
161161

162162
bullmq@^1.8.4:
163-
version "1.24.5"
164-
resolved "https://registry.yarnpkg.com/bullmq/-/bullmq-1.24.5.tgz#ecb501385b3bf3f56896ac7053c7c893b2f8fa39"
165-
integrity sha512-55RJ8rm174l2sFST03UC+Vac9k5MYsbMVsb86fVFqGRi2OKmfMPJgFvNFmCENHUyTE9nVToz2RXtnhw9gcyWVA==
163+
version "1.25.1"
164+
resolved "https://registry.yarnpkg.com/bullmq/-/bullmq-1.25.1.tgz#c9f07d435e088a8c627ffadd7b5f037719148b37"
165+
integrity sha512-eWPe2j9hmcKaWHPArqVihYwF96gD0NEA88nqHcr+KrVZpG26k3oab+Hv6Tpits0rCgjzFIsyfQ06XTla9sAtLQ==
166166
dependencies:
167167
"@types/ioredis" "^4.22.2"
168168
cron-parser "^2.7.3"
@@ -298,10 +298,10 @@ destroy@~1.0.4:
298298
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
299299
integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=
300300

301-
dotenv@^8.2.0:
302-
version "8.2.0"
303-
resolved "https://registry.npm.taobao.org/dotenv/download/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
304-
integrity sha1-l+YZJZradQ7qPk6j4mvO6lQksWo=
301+
dotenv@^9.0.2:
302+
version "9.0.2"
303+
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-9.0.2.tgz#dacc20160935a37dea6364aa1bef819fb9b6ab05"
304+
integrity sha512-I9OvvrHp4pIARv4+x9iuewrWycX6CcZtoAu1XrzPxc5UygMJXJZYmBsynku8IkrJwgypE5DGNjDPmPRhDCptUg==
305305

306306
ee-first@1.1.1:
307307
version "1.1.1"
@@ -699,8 +699,8 @@ moment-timezone@^0.5.31:
699699

700700
morgan@^1.10.0:
701701
version "1.10.0"
702-
resolved "https://registry.npm.taobao.org/morgan/download/morgan-1.10.0.tgz#091778abc1fc47cd3509824653dae1faab6b17d7"
703-
integrity sha1-CRd4q8H8R801CYJGU9rh+qtrF9c=
702+
resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.10.0.tgz#091778abc1fc47cd3509824653dae1faab6b17d7"
703+
integrity sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==
704704
dependencies:
705705
basic-auth "~2.0.1"
706706
debug "2.6.9"

0 commit comments

Comments
 (0)