即使在ember-cli中的适配器中设置主机,请求也会发送到页面域:
适配器/ students.js
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host:"localhost:8080/Hello"
});
路由/ students.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function(){
return this.store.find('students');
}
});
加载学生模板后,它会将请求发送到“localhost:4200 / students”并发出错误GET localhost:4200/students 404 (Not Found)
。该应用程序在localhost:4200上提供,但请求应发送到“localhost:8080 / Hello / students”。
答案 0 :(得分:2)
您的适配器文件应命名为adapters/application.js
。您还需要将适配器文件更新为以下内容:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host: 'http://localhost:8080',
namespace: 'Hello'
})
另外,请确保您正在启动此类应用程序:
ember server --proxy http://localhost:8080