Ember Fastboot redirect to external URL

327 Views Asked by At

I'm looking to 301 redirect to an external URL from within an Ember Route in Fastboot (based on the data returned by model()).

A solution, would be to access Express.js response object from within Ember, so I can call something like:

res.redirect(301, 'http://external-domain.com')?

However, I'm not entirely sure how res object can be accessed from within Ember. Fastboot exposes a response object, but it's not the same as the Express res.

1

There are 1 best solutions below

0
Sbbs On

The following code will redirect both in Fastboot and in the browser:

if (this.get('fastboot.isFastBoot')) {
  this.get('fastboot.response.headers').set('location', 'http://google.com');
  this.set('fastboot.response.statusCode', 302);
} else {
  window.location.replaceWith('http://google.com');
}