Skip to content
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

Omit standard protocol ports from the default hostname #1543

Merged
merged 3 commits into from
Sep 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions packages/authentication-oauth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,32 @@ export const setup = (options: OauthSetupSettings) => (app: Application) => {
}

const { strategyNames } = service;

// Set up all the defaults
const { path = '/oauth' } = oauth.defaults || {};
const port = app.get('port');
let host = app.get('host');
let protocol = 'https';

// Development environments commonly run on HTTP with an extended port
if (app.get('env') === 'development') {
protocol = 'http';
if (String(port) !== '80') {
host += ':' + port;
}
}

const grant = merge({
defaults: {
path,
host: `${app.get('host')}:${app.get('port')}`,
protocol: app.get('env') === 'production' ? 'https' : 'http',
host,
protocol,
transport: 'session'
}
}, omit(oauth, 'redirect'));

const getUrl = (url: string) => {
const { defaults } = grant;

return `${defaults.protocol}://${defaults.host}${path}/${url}`;
};

Expand Down