ember demo ember-cli-mirage在没有后端的服务器上不起作用

时间:2016-03-19 14:10:19

标签: ember.js ember-cli-mirage

我正在准备我的新ember应用程序的演示,暂时将其部署到静态http服务器,没有适当的后端。

我已经将项目配置为从海市蜃楼获取数据,并且它在本地运行良好。

问题在于,当我将它上传到我的http服务器时,海市蜃楼似乎不起作用,并且演示提出:

vendor-1bce2a3….js:11 Error while processing route: activities Ember Data Request GET /activities returned a 404
Payload (text/html)
[Omitted Lengthy HTML] Error: Ember Data Request GET /activities returned a 404
Payload (text/html)
[Omitted Lengthy HTML]
    at new Error (native)
    at Error.r (http://www.my-domain.com/myproject/assets/vendor-1bce2a36ef171f16e76daffe157c9b37.js:8:14790)
    at Error.n (http://www.my-domain.com/myproject/assets/vendor-1bce2a36ef171f16e76daffe157c9b37.js:19:25963)
    at e.default.r.default.extend.handleResponse (http://www.my-domain.com/myproject/assets/vendor-1bce2a36ef171f16e76daffe157c9b37.js:22:29329)
    at c.error (http://www.my-domain.com/myproject/assets/vendor-1bce2a36ef171f16e76daffe157c9b37.js:22:29898)
    at u (http://www.my-domain.com/myproject/assets/vendor-1bce2a36ef171f16e76daffe157c9b37.js:2:9669)
    at Object.c.fireWith (http://www.my-domain.com/myproject/assets/vendor-1bce2a36ef171f16e76daffe157c9b37.js:2:10437)
    at n (http://www.my-domain.com/myproject/assets/vendor-1bce2a36ef171f16e76daffe157c9b37.js:3:13352)
    at XMLHttpRequest.<anonymous> (http://www.my-domain.com/myproject/assets/vendor-1bce2a36ef171f16e76daffe157c9b37.js:3:19180)

这是我对海市蜃楼的配置:

// app/mirage/config.js
export default function() {

  this.get('/activities', function(db, request) {
    return { 'activity': db.activity };
  });

  this.get('/activities/:id', function(db, request) {
    var id = request.params.id;
    return { 'activity': db.activity.find(id) };
  });
}

它可以在我的本地机器上查找,但它不能在http服务器上运行,有关如何使该演示工作的任何想法?

谢谢,

2 个答案:

答案 0 :(得分:2)

默认情况下,在production版本中禁用Mirage。您可以使用ENV选项启用它:

// app/config/environment.js
...
if (environment === 'production') {
  ENV['ember-cli-mirage'] = {
    enabled: true
  }
}

有关详细信息,请参阅文档:http://www.ember-cli-mirage.com/docs/v0.1.x/server-configuration/#enabled

答案 1 :(得分:0)

既然你说你可以使用PHP,你可能会使用Apache,并且需要改变处理使用html5 pushState的请求的方式...如果你还没有/myprojectFallbackResource /myproject/index.html 目录中创建文件,并将其包含在内:

class Company extends Model {
   public function address() {
         return $this->belongsTo('App\Address', 'addressid');
 } }

这将使Apache传递对指定路径不存在(并且通常会产生404)的任何请求...