Search code examples
ember.jsnginxember-cli-mirage

Nginx not getting file available on route through Ember.js


Works on local and github pages but with nginx. Even on nginx I can properly get the json file from the browser, just not within the ember app on nginx.

export default Ember.Route.extend({
  model: function () {
      return $.getJSON('data/contributors.json')
  }
})

Results in this error only on Nginx:

server.js:76 Mirage: Your Ember app tried to GET 'data/contributors.json', but there was no route defined to handle this request. Define a route that matches this path in your mirage/config.js file. Did you forget to add your namespace?

location config on nginx:

location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
            try_files $uri /index.html;

    }

    location /data {
            try_files $uri /contributors.json
    }

config/environment.js

if (environment === 'internal') {
ENV.baseURL = '/'
ENV['ember-cli-mirage'] = {
  enabled: true
}
ENV.mirageNamespace = '<ip address>'
ENV.isProd = true
ENV.isDemo = true

}

Any help in resolving the error is much appreciated.


Solution

  • You have Mirage enabled, which is intercepting network requests and handling them itself. If you're deploying your app, you should be doing a build with --environment production, which by default disables Mirage.

    If you're enabling Mirage manually for some reason but you don't want this behavior, you can add this.passthrough() at the bottom of your mirage/config.js file to allow the request to actually hit the network.