我有一个React前端,它使用jwt与Django后端进行身份验证.后端工作正常,使用django视图连接正常,但当我try 代理React的请求时,它会给我一个连接拒绝错误.
代理错误:无法代理请求/api/auth/token/Acquire/from localhost:3000到http://localhost:8000(Econrefused).
连接到http://localhost:8000/api/auth/token/obtain/正常工作.使用Axios发送POST请求也可以正常工作,并返回标记json.但当我用node代理它时,它就不起作用了.
在我的package.json
年中,我有:
"proxy": {
"/api/*": {
"target": "http://localhost:8000"
}
},
编辑:Public repo.如果安装了docker,您可以轻松运行.(使用1个图像和2个容器).克隆后只需运行docker-compose build
,然后运行docker-compose up
.
Edit2:请求的标题:
*General*
Request URL: http://localhost:3000/api/auth/token/obtain/
Request Method: POST
Status Code: 500 Internal Server Error
Remote Address: [::1]:3000
Referrer Policy: no-referrer-when-downgrade
*Response Headers*
HTTP/1.1 500 Internal Server Error
X-Powered-By: Express
Date: Mon, 30 Apr 2018 21:23:17 GMT
Connection: keep-alive
Transfer-Encoding: chunked
*Request Headers
POST /api/auth/token/obtain/ HTTP/1.1
Host: localhost:3000
Connection: keep-alive
Content-Length: 45
Pragma: no-cache
Cache-Control: no-cache
Origin: http://localhost:3000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Content-Type: application/json
Accept: */*
Referer: http://localhost:3000/login
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,fr;q=0.8,ja;q=0.7