ember-cli --proxy 适用于 GET 但在 PUT 和 POST 上失败 [英] ember-cli --proxy works for GET but fails on PUT and POST

查看:23
本文介绍了ember-cli --proxy 适用于 GET 但在 PUT 和 POST 上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的应用程序从 Ember Appkit 移动到 ember-cli,但我无法复制以前由 APIMethod 和 proxyURL 方法提供的代理功能.

I'm trying to move my application from Ember Appkit to ember-cli and I'm having trouble replicating the proxy functionality previously provided by the APIMethod and proxyURL methods.

我正在启动服务器以代理到 localhost:3000

I'm starting the server to proxy to localhost:3000

ember serve --proxy http://localhost:3000/

这将正确地从 rails 服务器读取我的数据.但是,当我尝试写入服务器时,收到一条错误消息

This will read my data from the rails server correctly. However, when I try to write to the server, I get an error message

POST http://localhost:4200/api/v1/posts 408(请求超时)

它正在尝试发布到端口 4200,这是为 ember 应用程序提供服务的地方,但我希望它发布到端口 3000.我怎样才能做到这一点?

It's trying to post to port 4200, which is where the ember app is being served, but I want it to post to port 3000. How can I get it to do so?

我使用的是 ember-cli 0.28、ember 1.5.1、ember-data 1.0.0-beta.7 和 rails 4.1.

I'm using ember-cli 0.28, ember 1.5.1, ember-data 1.0.0-beta.7, and rails 4.1.

推荐答案

解决方案是将 server/index.js 中的 app.use(bodyParser()); 注释掉

The solution was to comment out app.use(bodyParser()); in server/index.js

这篇关于ember-cli --proxy 适用于 GET 但在 PUT 和 POST 上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆