【发布时间】:2020-01-28 08:13:04
【问题描述】:
我的 Ember 应用程序中有一个组件,它从静态降价文件返回数据。
didInsertElement() {
fetch('markdown/faqs-content.md').then(response => {
response.text().then(result => {
this.set('markdown', result);
});
});
}
应用运行时,请求转到http://localhost:4200/markdown/faqs-content.md,一切正常。
但是,在海市蜃楼中,我得到了这个错误:
Mirage: Your app tried to GET '/markdown/faqs-content.md', but there was no route defined to handle this request. Define a route for this endpoint in your routes() config. Did you forget to define a namespace?
即使mirage/config.js 中包含以下内容,也会发生上述情况:
this.passthrough();
推测这是因为请求 URL 中没有包含 API 命名空间。
可以通过添加完整的URL来解决问题:
this.passthrough('https://localhost:4201/markdown/faqs-content.md');
这样做有两个问题:
- 我并不总是知道应用程序所在的端口,并且
- 我不想失去使用
this.passThrough()的功能,它会自动为mirage/config.js中没有相应路由的任何API 请求调用传递。
因此我有 2 个问题。
在
config.js中,有没有办法获取Ember 服务器运行的端口,以允许https://localhost:${port}/markdown/faqs-content.md之类的东西?有没有一种方法可以将 Mirage 配置为传递给
https://localhost:4201/markdown/faqs-content.md的请求,并且仍然允许它传递给未定义相应路由的任何其他请求?
【问题讨论】: