From 4172da6911dd3ef9cee7094837f7c3066dc4a40a Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 17 Jun 2025 15:23:46 +0200 Subject: [PATCH] fix(cypress): intercept and rewrite wrong api requests --- frontend/cypress/support/e2e.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frontend/cypress/support/e2e.ts b/frontend/cypress/support/e2e.ts index 7b0c56d18..31a08423c 100644 --- a/frontend/cypress/support/e2e.ts +++ b/frontend/cypress/support/e2e.ts @@ -2,6 +2,18 @@ import './commands' import '@4tw/cypress-drag-drop' +beforeEach(() => { + // More comprehensive intercept for all API requests to dev server + cy.intercept('GET', '**/api/v1/**', (req) => { + // If the request is going to the dev server, redirect to API server + if (req.url.includes('127.0.0.1:4173') || req.url.includes('localhost:4173')) { + const newUrl = req.url.replace(/https?:\/\/(127\.0\.0\.1|localhost):4173\/api\/v1/, Cypress.env('API_URL')) + console.log('Redirecting request from', req.url, 'to', newUrl) + req.url = newUrl + } + }).as('apiRequest') +}) + // see https://github.com/cypress-io/cypress/issues/702#issuecomment-587127275 Cypress.on('window:before:load', (win) => { // disable service workers