Skip to content

Commit

Permalink
Make base path configurable and notify upon startup when used
Browse files Browse the repository at this point in the history
  • Loading branch information
bkimminich committed Mar 27, 2020
1 parent 0da0bd9 commit 7d16b33
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config.schema.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
server:
port:
type: number
basePath:
type: string
application:
domain:
type: string
Expand Down
1 change: 1 addition & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
server:
port: 3000
basePath: ''
application:
domain: juice-sh.op
name: 'OWASP Juice Shop'
Expand Down
4 changes: 2 additions & 2 deletions routes/profileImageFileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ module.exports = function fileUpload () {
}).catch(error => {
next(error)
})
res.location((process.env.BASE_PATH || '') + '/profile')
res.redirect((process.env.BASE_PATH || '') + '/profile')
res.location(process.env.BASE_PATH + '/profile')
res.redirect(process.env.BASE_PATH + '/profile')
} else {
next(new Error('Blocked illegal activity by ' + req.connection.remoteAddress))
}
Expand Down
4 changes: 2 additions & 2 deletions routes/profileImageUrlUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function profileImageUrlUpload () {
next(new Error('Blocked illegal activity by ' + req.connection.remoteAddress))
}
}
res.location((process.env.BASE_PATH || '') + '/profile')
res.redirect((process.env.BASE_PATH || '') + '/profile')
res.location(process.env.BASE_PATH + '/profile')
res.redirect(process.env.BASE_PATH + '/profile')
}
}
4 changes: 2 additions & 2 deletions routes/updateUserProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function updateUserProfile () {
} else {
next(new Error('Blocked illegal activity by ' + req.connection.remoteAddress))
}
res.location((process.env.BASE_PATH || '') + '/profile')
res.redirect((process.env.BASE_PATH || '') + '/profile')
res.location(process.env.BASE_PATH + '/profile')
res.redirect(process.env.BASE_PATH + '/profile')
}
}
6 changes: 5 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,13 @@ exports.start = async function (readyCallback) {
await models.sequelize.sync({ force: true })
await datacreator()
const port = process.env.PORT || config.get('server.port')
process.env.BASE_PATH = process.env.BASE_PATH || config.get('server.basePath')

server.listen(port, () => {
logger.info(colors.cyan(`Server listening on port ${port}`))
logger.info(colors.cyan(`Server listening on port ${colors.bold(port)}`))
if (process.env.BASE_PATH !== '') {
logger.info(colors.cyan(`Server using proxy base path ${colors.bold(process.env.BASE_PATH)} for redirects`))
}
require('./lib/startup/registerWebsocketEvents')(server)
if (readyCallback) {
readyCallback()
Expand Down

0 comments on commit 7d16b33

Please sign in to comment.