0

First of all I double checked at the other questions (see Invalid Host Header when ngrok tries to connect to React dev server) and I'm opening a new one because no solution helped me.

I'm running a Koa server with @koa/cors middleware (reproducible here):

import Koa from 'koa';
import KoaCors from '@koa/cors';

const app = new Koa();
app.proxy = true;
const PORT = 3030;
app.use(
  KoaCors({
    origin: '*',
    credentials: true,
  }),
);

app.listen(PORT);

I have a frontend application (Vite for React) from which I make calls to this backend.

Everything works perfectly: I can use everything locally (both backend and frontend) and I can use my backend by deploying online (for example on Google Cloud) and it also works by connecting with the frontend locally (obviously by changing the url for calls bees).

For testing purposes I have to "expose" my local backend to allow others to log in for quick debugging and fixes. I opted for ngrok: if I launch the proxy with "ngrok http 3030" I can easily connect from postman using the public address provided by ngrok and it works, but if I connect from the frontend, I always get a CORS Preflight error:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Already tried using --host-header=rewrite , already fixed headers in request (ngrok-skip-browser-warning), but nothing is working for me.

Any idea?

crivella
  • 514
  • 5
  • 19

0 Answers0