【问题标题】:Nginx not getting file available on route through Ember.jsNginx 没有通过 Ember.js 获取可用的文件
【发布时间】:2016-04-04 20:56:42
【问题描述】:

适用于本地和 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

}

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

【问题讨论】:

    标签: ember.js nginx ember-cli-mirage


    【解决方案1】:

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

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

    【讨论】:

    • 我有这个,但它不起作用。如果我只是做ember build,Nginx 服务器确实可以工作......(我还将我的 environment.js 文件添加到问题中)
    • 您的 API/Ember 数据适配器的主机是否指定给服务于 ember 应用程序的域以外的其他对象?如果是这样,您需要在对 passthrough 的调用中指定该域,例如this.passthrough('my.api.com/**')
    猜你喜欢
    • 1970-01-01
    • 2013-11-08
    • 2019-05-20
    • 2018-01-28
    • 1970-01-01
    • 2014-02-07
    • 2011-09-14
    • 2013-04-25
    • 1970-01-01
    相关资源
    最近更新 更多