How to link React Native (expo) app with Nest js?

552 Views Asked by At

After setting the nest js project and verifying all routes using insomnia I've tried enabling cors

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.enableCors()
  await app.listen(3001);

}
bootstrap();

but I still get Network Error

the problem seems like from the Nest js project (cors specifically) because I tryied linking the same nest js project with react js project and everything was going fine .

Otherwise,in react native when trying something like

const res = await axios.get("https://www.google.com/")
      .then(res => console.log(res.data))
      .catch(err => console.error(err));

i get all the data in the log

2

There are 2 best solutions below

3
Brice Zele On BEST ANSWER

Try to use instead of the local address http://localhost:3001 your local IP address like: http://192.168.xxx.xxx:3001

1
Just Ir Dab On

try this link https://docs.nestjs.com/security/cors it gives more ways to activate cors