正在拿cnode练手react。官方脚手架create-react-app生成项目设置proxy时,一直报500。
package.json:
“proxy”: {
"/api/v1": {
“target”: “https://cnodejs.org”
}
}
header:
authority:localhost:3000
method:GET
path:/api/v1/message/count?accesstoken=3f39953f-cfb4-4a84-ba6a-b0132c448965
scheme:https
accept:/
accept-encoding:gzip, deflate, sdch, br
accept-language:zh-CN,zh;q=0.8
cache-control:no-cache
pragma:no-cache
referer:https://localhost:3000/
user-agent:Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
npm error:
Proxy error:** Could not proxy request /api/v1/message/count?accesstoken=3f39953f- cfb4-4a84-ba6a-b0132c448965 from localhost:3000 to https://cnodejs.org. See https://nodejs.org/api/errors.html#errors_common_system_errors for more info rmation (undefined).**
[HPM] Error occurred while trying to proxy request /api/v1/message/count?accesst oken=3f39953f-cfb4-4a84-ba6a-b0132c448965 from localhost:3000 to https://cnodejs .org (undefined) (https://nodejs.org/api/errors.html#errors_common_system_errors )
自问自答,尴尬! conde提供的接口是基于HTTPS,所以package.json中proxy得多一项配置secure=false。 扒了下react-scripts/react-scripts/start.js,发现最后proxy是作为webpack-dev-server的proxy配置。再重新翻了webpack-dev-server的文档。找到是因为secure=false原因。 丢人了!