Merge pull request #1118 from theseyi/secure-redirect

redirects to https from unsecure locations on app transition
This commit is contained in:
Seyi Adebajo 2018-05-03 10:40:21 -07:00 committed by GitHub
commit 6120e2a6e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View File

@ -2,7 +2,8 @@ import Router from '@ember/routing/router';
import { get, getWithDefault } from '@ember/object';
import { inject as service } from '@ember/service';
import { scheduleOnce } from '@ember/runloop';
import config from './config/environment';
import config from 'wherehows-web/config/environment';
import { redirectToHttps } from 'wherehows-web/utils/build-url';
const AppRouter = Router.extend({
location: config.locationType,
@ -11,6 +12,15 @@ const AppRouter = Router.extend({
metrics: service(),
willTransition() {
const { APP: { useSecureRedirect } } = config;
this._super(...arguments);
if (useSecureRedirect) {
redirectToHttps(window.location);
}
},
didTransition() {
this._super(...arguments);

View File

@ -39,3 +39,15 @@ export default (baseUrl: string, queryParam: string, queryValue: string): string
return `${baseUrl}${separator}${queryParam}=${queryValue}`;
};
/**
* Sets the href on a location object if the protocol is not https
* @param {Location} { protocol, href }
*/
export const redirectToHttps = ({ protocol, href, hostname }: Location): void => {
const secureProtocol = 'https:';
if (protocol !== secureProtocol && hostname !== 'localhost') {
window.location.replace(`${secureProtocol}${href.substring(protocol.length)}`);
}
};

View File

@ -18,8 +18,7 @@ module.exports = function(environment) {
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
useSecureRedirect: true
},
eyeglass: {