Nginx 无法在通过 Ember.js 的路径上获取可用文件

Nginx not getting file available on route through Ember.js

适用于本地和 github 页面,但使用 nginx。即使在 nginx 上,我也可以从浏览器中正确获取 json 文件,只是不在 nginx 上的 ember 应用程序中。

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

仅在 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?

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

}

非常感谢任何解决错误的帮助。

您启用了 Mirage,它正在拦截网络请求并自行处理它们。如果您正在部署您的应用程序,您应该使用 --environment production 进行构建,这在默认情况下会禁用 Mirage。

如果您出于某种原因手动启用 Mirage 但不希望出现这种情况,您可以在 mirage/config.js 文件的底部添加 this.passthrough() 以允许请求实际命中网络。