Skip to content

Commit ef16d29

Browse files
compwrightdaffl
authored andcommitted
fix: Omit standard protocol ports from the default hostname (#1543)
1 parent 19259dd commit ef16d29

File tree

1 file changed

+17
-3
lines changed
  • packages/authentication-oauth/src

1 file changed

+17
-3
lines changed

packages/authentication-oauth/src/index.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,32 @@ export const setup = (options: OauthSetupSettings) => (app: Application) => {
2424
}
2525

2626
const { strategyNames } = service;
27+
28+
// Set up all the defaults
2729
const { path = '/oauth' } = oauth.defaults || {};
30+
const port = app.get('port');
31+
let host = app.get('host');
32+
let protocol = 'https';
33+
34+
// Development environments commonly run on HTTP with an extended port
35+
if (app.get('env') === 'development') {
36+
protocol = 'http';
37+
if (String(port) !== '80') {
38+
host += ':' + port;
39+
}
40+
}
41+
2842
const grant = merge({
2943
defaults: {
3044
path,
31-
host: `${app.get('host')}:${app.get('port')}`,
32-
protocol: app.get('env') === 'production' ? 'https' : 'http',
45+
host,
46+
protocol,
3347
transport: 'session'
3448
}
3549
}, omit(oauth, 'redirect'));
50+
3651
const getUrl = (url: string) => {
3752
const { defaults } = grant;
38-
3953
return `${defaults.protocol}://${defaults.host}${path}/${url}`;
4054
};
4155

0 commit comments

Comments
 (0)