From fac77662a110909cd783b46d51b3f0ce5f698c12 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Wed, 21 Aug 2019 23:41:19 -0700 Subject: [PATCH 1/3] Make /install work under FastBoot --- app/routes/install.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/routes/install.js b/app/routes/install.js index 7c52f9ce3da..668ec895ee4 100644 --- a/app/routes/install.js +++ b/app/routes/install.js @@ -1,7 +1,20 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; export default Route.extend({ + fastboot: service(), + redirect() { - window.location = 'https://doc.rust-lang.org/cargo/getting-started/installation.html'; + this._redirectTo('https://doc.rust-lang.org/cargo/getting-started/installation.html'); + }, + + _redirectTo(url) { + if (this.fastboot.isFastBoot) { + let headers = this.fastboot.response.headers; + headers.set('location', url); + this.set('fastboot.response.statusCode', 301); + } else { + window.location = url; + } }, }); From 952e8ba5729a83bd5d672ad6abb4813a9b66b67f Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Mon, 25 Nov 2019 20:55:36 -0800 Subject: [PATCH 2/3] Extract the redirection logic to a new service The service can be used from other routes that modify window.location. --- app/routes/install.js | 14 ++------------ app/services/redirector.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 app/services/redirector.js diff --git a/app/routes/install.js b/app/routes/install.js index 668ec895ee4..972a971285b 100644 --- a/app/routes/install.js +++ b/app/routes/install.js @@ -2,19 +2,9 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; export default Route.extend({ - fastboot: service(), + redirector: service(), redirect() { - this._redirectTo('https://doc.rust-lang.org/cargo/getting-started/installation.html'); - }, - - _redirectTo(url) { - if (this.fastboot.isFastBoot) { - let headers = this.fastboot.response.headers; - headers.set('location', url); - this.set('fastboot.response.statusCode', 301); - } else { - window.location = url; - } + this.redirector.redirectTo('https://doc.rust-lang.org/cargo/getting-started/installation.html'); }, }); diff --git a/app/services/redirector.js b/app/services/redirector.js new file mode 100644 index 00000000000..8a382d2d1cc --- /dev/null +++ b/app/services/redirector.js @@ -0,0 +1,15 @@ +import Service, { inject as service } from '@ember/service'; + +export default Service.extend({ + fastboot: service(), + + redirectTo(url) { + if (this.fastboot.isFastBoot) { + let headers = this.fastboot.response.headers; + headers.set('location', url); + this.set('fastboot.response.statusCode', 301); + } else { + window.location = url; + } + }, +}); From 976e8e82b5781b287841fbbc14e8356dd3ed6ddb Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Mon, 25 Nov 2019 20:56:15 -0800 Subject: [PATCH 3/3] Use Redirector service instead of setting window.location That makes the routes work under FastBoot. --- app/routes/crate/docs.js | 3 ++- app/routes/crate/repo.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/routes/crate/docs.js b/app/routes/crate/docs.js index 2579eb95e9e..f978d12210a 100644 --- a/app/routes/crate/docs.js +++ b/app/routes/crate/docs.js @@ -3,13 +3,14 @@ import { inject as service } from '@ember/service'; export default Route.extend({ flashMessages: service(), + redirector: service(), redirect() { let crate = this.modelFor('crate'); let documentation = crate.get('documentation'); if (documentation) { - window.location = documentation; + this.redirector.redirectTo(documentation); } else { // Redirect to the crate's main page and show a flash error if // no documentation is found diff --git a/app/routes/crate/repo.js b/app/routes/crate/repo.js index 8ff337aadf5..97cbc5fa3e3 100644 --- a/app/routes/crate/repo.js +++ b/app/routes/crate/repo.js @@ -3,13 +3,14 @@ import { inject as service } from '@ember/service'; export default Route.extend({ flashMessages: service(), + redirector: service(), redirect() { let crate = this.modelFor('crate'); let repository = crate.get('repository'); if (repository) { - window.location = repository; + this.redirector.redirectTo(repository); } else { // Redirect to the crate's main page and show a flash error if // no repository is found