使用 POST 方法在 Ember-cli 中保存新记录不起作用

Saving new record in Ember-cli using POST mehod is not working

我正在使用 ember-cli 和 ember-data 1.8。1.I 在 hapijs 中写了 api。 问题是当我创建新记录并保存 it.then 时,它应该是 POST 请求,但它发送方法 'OPTIONS',并说 404 未找到。 我发现控制台中的错误是:-

[Report Only] Refused to connect to 'http://localhost:3000/users' because it violates the following Content Security Policy directive: "connect-src 'self' ws://localhost:35729 ws://0.0.0.0:35729"

OPTIONS http://localhost:3000/users 

XMLHttpRequest cannot load http://localhost:3000/users. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 404.

所以这是我为保存记录而写的代码

var onSuccess = function(post) {
              console.log(post);
            };
var onFail = function(post) {
              console.log("fail");
              console.log(post);
            };    
var user = store.createRecord('user', {
            email : "Email",
            phone : "phone",
            password : 'password',
            "isd_code_id" : 1,
            slug: "puneet"
          });

 user.save().then(onSuccess, onFail);

它总是失败,我已经在 hapijs 中添加了 cors,GET 请求正在运行 fine.Only 问题是保存记录。 请帮助我应该怎么做才能让它工作

hapi 8.0 中的 CORS 配置已更改,因此您可能使用的是旧配置。这是在 hapi 8.0 中启用 CORS 的方法:

var server = new Hapi.Server({
    connections: {
        routes: {
            cors: true
        }
    }
});