Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
932 views
in Technique[技术] by (71.8m points)

400 Bad Request when Angular app uses local dev API in Cypress.io tests

When running Cypress.io tests in my dev environment, I'm getting this error when sending any requests to my local API (localhost). External APIs work and the code runs fine outside the context of Cypress tests.

cypress_runner.js:177238 GET http://localhost:4444/apicallname 400 (Bad Request)
XHR.send @ cypress_runner.js:177238
scheduleTask @ VM478 polyfills.js:2943
...
error @ VM479 vendor.js:32379
VM480 main.js:11997 Error:  {"_body":"WebSockets request was expected
","status":400,"ok":false,"statusText":"Bad Request","headers":{"connection":["keep-alive"],"content-encoding":["gzip"],"content-type":["text/html; charset=UTF-8"],"date":["Fri"," 01 Jan 2021 00:44:22 GMT"],"transfer-encoding":["chunked"],"vary":["Accept-Encoding"]},"type":2,"url":"http://localhost:4444/apicallname"}

I haven't had this issue before so I'm pretty confused why it's happening now. The same call with the same auth token works in Postman. The Node.js API I'm calling is not returning an error.

Update: If I use the machine's IP instead of "localhost" it works, but that's not ideal of course.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...