Ember-cli-fastboot incompatibility with existing ember app


#1

I have an existing ember application. I am trying to make it fastboot compatible. However, fastboot is unable to serve the page statically. After digging through the code, I found this snippet which is causing the issue.

    if (broccoliHeader['url'] === req.serveUrl && enableFastBootServe) {
      // if it is a base page request, then have fastboot serve the base page
      if (!this.fastboot) {
        // TODO(future): make this configurable for allowing apps to pass sandboxGlobals
        // and custom sandbox class
        this.ui.writeLine(chalk.green('App is being served by FastBoot'));
        this.fastboot = new FastBoot({
          distPath: outputPath
        });
      }

      let fastbootMiddleware = FastBootExpressMiddleware({
        fastboot: this.fastboot
      });

      fastbootMiddleware(req, resp, next);
    } else {
      // forward the request to the next middleware (example other assets, proxy etc)
      next();
    }

I have found that for my App, req.serveUrl is always undefined. Can anyone help me understand why that is the case and how to fix it.

I am using ember-cli 2.13.2


#2

Which ember-cli-fastboot version? Please take note of the breaking changes in the more recent versions, I’ve got mine in production pegged to 1.0.0-beta.19


#3

@The_Don_Himself This is my first attempt to use ember fastboot. I am using version ^1.0.0-rc.3


#4

Ok, then there might a little bit of learning for you to do first, but its not hard. fastboot-app-server just serves up an express middleware specifically tuned for ember apps. Check out all available req methods here https://expressjs.com/en/api.html#req I think your issue is that the method req.serveUrl does not exist, try req.url instead.


#5

@The_Don_Himself The code that I pasted in ember-cli-fastboot code. I don’t control it. I was trying to find the cause of my issue that fastboot wont work for my app


#6

@tomdale Any ideas how I can fix ember-cli-fastboot req.serveUrl. Is there any ENV config?


#7

I was able to track down where req.serveUrl is set. I found that the ember cli adds middleware in following cases.

  1. locationType is set to ‘auto’ or 'history’ Or
  2. historySupportMiddlewar ENV is set

Since I am using proxy in my dev environment, i had locationType set to ‘hash’.

So I solved the issue by setting historySupportMiddleware to true for dev environment only

Thanks @The_Don_Himself for pointing me to the req documentation. When I saw that by default serveUrl does not exist, only then I thought of figuring out where it is getting set.