适用于本地和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
}
配置/ environment.js
if (environment === 'internal') {
ENV.baseURL = '/'
ENV['ember-cli-mirage'] = {
enabled: true
}
ENV.mirageNamespace = '<ip address>'
ENV.isProd = true
ENV.isDemo = true
}
非常感谢您解决错误的任何帮助。
答案 0 :(得分:0)
您启用了Mirage,它拦截网络请求并自行处理它们。如果您正在部署应用,则应使用--environment production
进行构建,默认情况下禁用幻影。
如果由于某种原因您手动启用Mirage但您不想要此行为,则可以在this.passthrough()
文件的底部添加mirage/config.js
以允许请求实际上是打网络了。