redirects to https for unsecure locations on app transition

This commit is contained in:
Seyi Adebajo 2018-04-24 11:26:12 -07:00
parent 19ff87dee6
commit 1d6f78d355
2 changed files with 19 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import { get, getWithDefault } from '@ember/object';
import { inject as service } from '@ember/service';
import { scheduleOnce } from '@ember/runloop';
import config from './config/environment';
import { redirectToHttps } from 'wherehows-web/utils/build-url';
const AppRouter = Router.extend({
location: config.locationType,
@ -11,6 +12,12 @@ const AppRouter = Router.extend({
metrics: service(),
willTransition() {
this._super(...arguments);
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)}`);
}
};