[{"data":1,"prerenderedAt":82},["ShallowReactive",2],{"/2026/02/11-cypress-connection-refused-error":3},{"id":4,"title":5,"body":6,"date":73,"description":44,"extension":74,"meta":75,"navigation":76,"path":77,"robots":78,"seo":79,"stem":80,"__hash__":81},"posts/2026/02/11 Cypress-connection-refused-error.md","11 Cypress Connection Refused Error",{"type":7,"value":8,"toc":70},"minimark",[9,18,25,28,31,45,47,50,52,55,57,60,62,65,67],[10,11,13],"post-title",{":date":12},"date",[14,15,17],"h1",{"id":16},"cypress-connection-refused-error","Cypress Connection Refused Error",[19,20,21],"notes",{},[22,23,24],"p",{},"This is a repost from my old blog. First posted in 2/26/2025.",[26,27],"br",{},[22,29,30],{},"I had a case where I need to call an api then visit the app in Cypress and it turns out to be causing an issue with the following error message:",[32,33,34],"code-block",{},[35,36,41],"pre",{"className":37,"code":39,"language":40},[38],"language-text","Error: connect ECONNREFUSED 127.0.0.1:4200\n","text",[42,43,39],"code",{"__ignoreMap":44},"",[26,46],{},[22,48,49],{},"It turns out to be Cypress' origin safety issue. I wrapped the cy.request() with cy.origin() and that solves the issue with a catch.",[26,51],{},[22,53,54],{},"If I call cy.origin() before I call cy.visit() then it doesn't work somehow.",[26,56],{},[22,58,59],{},"If I call cy.visit() first and then cy.origin() then it works fine.",[26,61],{},[22,63,64],{},"Also, if after code change, it doesn't appear to work, restart cypress app (or test runner if using older version).",[26,66],{},[22,68,69],{},"I had the case where I call cy.origin() first, then cy.visit() which doesn't work, make the change to call cy.visit() first without restarting the app and it still doesn't work. But it works after I restarted cypress app.",{"title":44,"searchDepth":71,"depth":71,"links":72},2,[],"2026-02-11T00:00:00.000Z","md",{},true,"/2026/02/11-cypress-connection-refused-error",null,{"title":5,"description":44},"2026/02/11 Cypress-connection-refused-error","_84B7Gq4lBJZmk7VI0trwpMr9VnmGoGBws1gwOPS0Dw",1785167451494]