1
votes

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

1 Answers

1
votes

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');
}