mirror of
https://github.com/datahub-project/datahub.git
synced 2025-10-29 17:59:24 +00:00
Merge pull request #1118 from theseyi/secure-redirect
redirects to https from unsecure locations on app transition
This commit is contained in:
commit
6120e2a6e2
@ -2,7 +2,8 @@ import Router from '@ember/routing/router';
|
|||||||
import { get, getWithDefault } from '@ember/object';
|
import { get, getWithDefault } from '@ember/object';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
import { scheduleOnce } from '@ember/runloop';
|
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({
|
const AppRouter = Router.extend({
|
||||||
location: config.locationType,
|
location: config.locationType,
|
||||||
@ -11,6 +12,15 @@ const AppRouter = Router.extend({
|
|||||||
|
|
||||||
metrics: service(),
|
metrics: service(),
|
||||||
|
|
||||||
|
willTransition() {
|
||||||
|
const { APP: { useSecureRedirect } } = config;
|
||||||
|
this._super(...arguments);
|
||||||
|
|
||||||
|
if (useSecureRedirect) {
|
||||||
|
redirectToHttps(window.location);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
didTransition() {
|
didTransition() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
||||||
|
|||||||
@ -39,3 +39,15 @@ export default (baseUrl: string, queryParam: string, queryValue: string): string
|
|||||||
|
|
||||||
return `${baseUrl}${separator}${queryParam}=${queryValue}`;
|
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)}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@ -18,8 +18,7 @@ module.exports = function(environment) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
APP: {
|
APP: {
|
||||||
// Here you can pass flags/options to your application instance
|
useSecureRedirect: true
|
||||||
// when it is created
|
|
||||||
},
|
},
|
||||||
|
|
||||||
eyeglass: {
|
eyeglass: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user