-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow overriding showLoginPage
config via request header
#336
feat: allow overriding showLoginPage
config via request header
#336
Conversation
2ed2aef
to
ffa7b8d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm otherwise!
index.js
Outdated
if (req.header('X-Show-Login-Page')) { | ||
return req.header('X-Show-Login-Page') === 'true' | ||
} | ||
return process.env.SHOW_LOGIN_PAGE === 'true' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about something more concise like..
if (req.header('X-Show-Login-Page')) { | |
return req.header('X-Show-Login-Page') === 'true' | |
} | |
return process.env.SHOW_LOGIN_PAGE === 'true' | |
return process.env.SHOW_LOGIN_PAGE === 'true' || req.header('X-Show-Login-Page') === 'true' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was actually to support a possible use case where the SHOW_LOGIN_PAGE
env is true
but the user wants to override it to false in a request via a header X-Show-Login-Page: false
.
This was my main use case:
This way, E2E tests can send
X-Show-Login-Page: false
in the request, while manual testing can still be done in the browser, all against the same running instance of Mockpass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered this form, but thought it might be a bit hard to understand:
showLoginPage: (req) =>
req.header('X-Show-Login-Page')
? req.header('X-Show-Login-Page') === 'true'
: process.env.SHOW_LOGIN_PAGE === 'true',
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh we could also do something like this:
showLoginPage: (req) =>
(req.header('X-Show-Login-Page') || process.env.SHOW_LOGIN_PAGE) === 'true',
Problem
SHOW_LOGIN_PAGE
environment variable tofalse
to overcome this, but then it becomes less suitable for manual testingSolution
showLoginPage
config to be overridden per request via anX-Show-Login-Page
HTTP headerX-Show-Login-Page: false
in the request, while manual testing can still be done in the browser, all against the same running instance of Mockpass