Skip to content

Commit

Permalink
Replace BASE_PATH with PROXY_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
Deadly0 committed May 15, 2021
1 parent 4c0c584 commit 9228290
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 83 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14.15-alpine
FROM node:14.17-alpine

WORKDIR /usr/app

Expand All @@ -14,6 +14,8 @@ ENV BULL_PREFIX bull
ENV BULL_VERSION BULLMQ
ENV USER_LOGIN ''
ENV USER_PASSWORD ''
ENV REDIS_DB 0
ENV PROXY_PATH ''

RUN yarn install

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ see "Example with docker-compose" section for example with env parameters
### Environment variables
* `REDIS_HOST` - host to connect to redis (localhost by default)
* `REDIS_PORT` - redis port (6379 by default)
* `REDIS_DB` - redis db ('0' by default)
* `REDIS_DB` - redis db to use ('0' by default)
* `REDIS_USE_TLS` - enable TLS true or false (false by default)
* `REDIS_PASSWORD` - password to connect to redis (no password by default)
* `BULL_PREFIX` - prefix to your bull queue name (bull by default)
* `BULL_VERSION` - version of bull lib to use 'BULLMQ' or 'BULL' ('BULLMQ' by default)
* `BASE_PATH` - basePath for bull board, e.g. '/bull-board' ('/' by default)
* `PROXY_PATH` - proxyPath for bull board, e.g. '/bull-board' ('' by default)
* `PROXY_PATH` - proxyPath for bull board, e.g. https://<server_name>/my-base-path/queues [docs] ('' by default)
* `USER_LOGIN` - login to restrict access to bull-board interface (disabled by default)
* `USER_PASSWORD` - password to restrict access to bull-board interface (disabled by default)

Expand Down Expand Up @@ -82,3 +81,4 @@ volumes:
```

[bull-board]: https://github.com/vcapretz/bull-board
[bull-board]: https://github.com/felixmosh/bull-board#hosting-router-on-a-sub-path
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"bull-board": "^2.0.3",
"bullmq": "^1.8.4",
"connect-ensure-login": "^0.1.1",
"dotenv": "^8.2.0",
"dotenv": "^9.0.2",
"express": "^4.17.1",
"express-session": "^1.17.1",
"morgan": "^1.10.0",
Expand Down
36 changes: 16 additions & 20 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
require('dotenv').config();

function normalizePath(pathStr) {
return (pathStr || '').replace(/\/$/, '');
return (pathStr || '').replace(/\/$/, '');
}

const BASE_PATH = normalizePath(process.env.BASE_PATH);
const PROXY_PATH = normalizePath(process.env.PROXY_PATH) + BASE_PATH;
const PROXY_PATH = normalizePath(process.env.PROXY_PATH);

const config = {
REDIS_PORT: process.env.REDIS_PORT || 6379,
REDIS_HOST: process.env.REDIS_HOST || 'localhost',
REDIS_DB: process.env.REDIS_DB || '0',
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
REDIS_USE_TLS: process.env.REDIS_USE_TLS,
BULL_PREFIX: process.env.BULL_PREFIX || 'bull',
BULL_VERSION: process.env.BULL_VERSION || 'BULLMQ',
PORT: process.env.PORT || 3000,
BASE_PATH: BASE_PATH,
PROXY_PATH: PROXY_PATH,
USER_LOGIN: process.env.USER_LOGIN,
USER_PASSWORD: process.env.USER_PASSWORD,
REDIS_PORT: process.env.REDIS_PORT || 6379,
REDIS_HOST: process.env.REDIS_HOST || 'localhost',
REDIS_DB: process.env.REDIS_DB || '0',
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
REDIS_USE_TLS: process.env.REDIS_USE_TLS,
BULL_PREFIX: process.env.BULL_PREFIX || 'bull',
BULL_VERSION: process.env.BULL_VERSION || 'BULLMQ',
PORT: process.env.PORT || 3000,
PROXY_PATH: PROXY_PATH,
USER_LOGIN: process.env.USER_LOGIN,
USER_PASSWORD: process.env.USER_PASSWORD,

AUTH_ENABLED: Boolean(process.env.USER_LOGIN && process.env.USER_PASSWORD),
HOME_PAGE: BASE_PATH || '/',
LOGIN_PAGE: `${BASE_PATH}/login`,
PROXY_HOME_PAGE: PROXY_PATH || '/',
PROXY_LOGIN_PAGE: `${PROXY_PATH}/login`,
AUTH_ENABLED: Boolean(process.env.USER_LOGIN && process.env.USER_PASSWORD),
HOME_PAGE: PROXY_PATH || '/',
LOGIN_PAGE: `${PROXY_PATH}/login`,
};

module.exports = config;
49 changes: 26 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const {authRouter} = require('./login');
const config = require('./config');

const redisConfig = {
redis: {
port: config.REDIS_PORT,
host: config.REDIS_HOST,
db: config.REDIS_DB,
...(config.REDIS_PASSWORD && {password: config.REDIS_PASSWORD}),
tls: config.REDIS_USE_TLS === 'true',
},
redis: {
port: config.REDIS_PORT,
host: config.REDIS_HOST,
db: config.REDIS_DB,
...(config.REDIS_PASSWORD && {password: config.REDIS_PASSWORD}),
tls: config.REDIS_USE_TLS === 'true',
},
};

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

if (app.get('env') !== 'production') {
const morgan = require('morgan');
app.use(morgan('combined'));
const morgan = require('morgan');
app.use(morgan('combined'));
}

app.use((req, res, next) => {
if (config.PROXY_PATH) req.proxyUrl = config.PROXY_PATH;
next();
if (config.PROXY_PATH) {
req.proxyUrl = config.PROXY_PATH;
}

next();
});

const sessionOpts = {
name: 'bull-board.sid',
secret: Math.random().toString(),
resave: false,
saveUninitialized: false,
cookie: {
path: '/',
httpOnly: false,
secure: false
}
name: 'bull-board.sid',
secret: Math.random().toString(),
resave: false,
saveUninitialized: false,
cookie: {
path: '/',
httpOnly: false,
secure: false
}
};

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

if (config.AUTH_ENABLED) {
app.use(config.LOGIN_PAGE, authRouter);
app.use(config.HOME_PAGE, ensureLoggedIn(config.PROXY_LOGIN_PAGE), router);
app.use(config.LOGIN_PAGE, authRouter);
app.use(config.HOME_PAGE, ensureLoggedIn(config.LOGIN_PAGE), router);
} else {
app.use(config.HOME_PAGE, router);
app.use(config.HOME_PAGE, router);
}

app.listen(config.PORT, () => {
Expand Down
30 changes: 15 additions & 15 deletions src/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ const config = require('./config');
const authRouter = express.Router();

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

return cb(null, false);
})
return cb(null, false);
})
);

passport.serializeUser((user, cb) => {
cb(null, user);
cb(null, user);
});

passport.deserializeUser((user, cb) => {
cb(null, user);
cb(null, user);
});

authRouter.route('/')
.get((req, res) => {
res.render('login');
})
.post(passport.authenticate('local', {
successRedirect: config.PROXY_HOME_PAGE,
failureRedirect: config.PROXY_LOGIN_PAGE,
}));
.get((req, res) => {
res.render('login');
})
.post(passport.authenticate('local', {
successRedirect: config.HOME_PAGE,
failureRedirect: config.LOGIN_PAGE,
}));

exports.authRouter = authRouter;
40 changes: 20 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"@types/serve-static" "*"

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

Expand All @@ -49,9 +49,9 @@
integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==

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

"@types/qs@*":
version "6.9.6"
Expand Down Expand Up @@ -103,8 +103,8 @@ balanced-match@^1.0.0:

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

Expand Down Expand Up @@ -144,9 +144,9 @@ bull-board@^2.0.3:
redis-info "^3.0.8"

bull@^3.13.0:
version "3.22.4"
resolved "https://registry.yarnpkg.com/bull/-/bull-3.22.4.tgz#1bda418d2aebdf892413d0c45d75c8ea5e0fc984"
integrity sha512-CV78TuSKyDj3SuZvySTOFXqZBtHxebhctLTq2Ff9Jrn51XOaxkEDioIDzq2LIUKEhTW8l3rFK5bIWNwweY0LXQ==
version "3.22.5"
resolved "https://registry.yarnpkg.com/bull/-/bull-3.22.5.tgz#ab42d76ecb7d8c5faba7a6a6e1d8b0ed0cde7ff5"
integrity sha512-wA5CRChiqF7bQ3/mLToFRiAKujWVBJJ07Ok368aiER8N1ail0veHwHc02I4lMMUyG9WoxHCHyrCqyPQhDGrd2w==
dependencies:
cron-parser "^2.13.0"
debuglog "^1.0.0"
Expand All @@ -160,9 +160,9 @@ bull@^3.13.0:
uuid "^8.3.0"

bullmq@^1.8.4:
version "1.24.5"
resolved "https://registry.yarnpkg.com/bullmq/-/bullmq-1.24.5.tgz#ecb501385b3bf3f56896ac7053c7c893b2f8fa39"
integrity sha512-55RJ8rm174l2sFST03UC+Vac9k5MYsbMVsb86fVFqGRi2OKmfMPJgFvNFmCENHUyTE9nVToz2RXtnhw9gcyWVA==
version "1.25.1"
resolved "https://registry.yarnpkg.com/bullmq/-/bullmq-1.25.1.tgz#c9f07d435e088a8c627ffadd7b5f037719148b37"
integrity sha512-eWPe2j9hmcKaWHPArqVihYwF96gD0NEA88nqHcr+KrVZpG26k3oab+Hv6Tpits0rCgjzFIsyfQ06XTla9sAtLQ==
dependencies:
"@types/ioredis" "^4.22.2"
cron-parser "^2.7.3"
Expand Down Expand Up @@ -298,10 +298,10 @@ destroy@~1.0.4:
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=

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

[email protected]:
version "1.1.1"
Expand Down Expand Up @@ -699,8 +699,8 @@ moment-timezone@^0.5.31:

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

0 comments on commit 9228290

Please sign in to comment.