Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.html() works unexpectedly for redirects when rendering fastboot on a cdn using fastboot.visit() #845

Open
hoIIer opened this issue Aug 14, 2021 · 0 comments

Comments

@hoIIer
Copy link
Contributor

hoIIer commented Aug 14, 2021

I'm rendering a fastboot page on a cdn like so:

          const res = await this.fastboot.visit(
            this.request.url,
            {request: this.request},
          );
          
          html = await res.html();
          ...

I have a route with nested child routes, and I want the index to redirect to the child like so:

  this.route('foo', function() {
    this.route('bar');
  });
import Route from '@ember/routing/route';

export default class FooIndexRoute extends Route {
  redirect() {
    this.transitionTo('foo.bar');
  }
}

When a user navigates directly to mysite.com/foo, fastboot hits this line and instead of rendering the redirected page, it returns an anchor link which exposes the cdn resource.

<h1>Redirecting to <a href="${location}">${location}</a></h1>

I was able to get around this using a small hack but wondering if we should include an optional param to html() that would tell fastboot to render the redirected page?

          const res = await this.fastboot.visit(
            this.request.url,
            {request: this.request},
          );

          if (res.statusCode >= 300 && res.statusCode <= 399) {
            // trick fastboot into thinking it was a successful request.
            res._fastbootInfo.response.statusCode = 200;
          }

          // render the pages html.
          html = await res.html();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant