如何将React Native(expo)应用程序与Nest.js连接?

huangapple go评论76阅读模式
英文:

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

问题

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

英文:

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

答案1

得分: 0

尝试此链接 https://docs.nestjs.com/security/cors
它提供了更多激活跨源资源共享 (CORS) 的方法。

英文:

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

答案2

得分: 0

尝试使用本地 IP 地址而不是本地地址 http://localhost:3001,类似于:http://192.168.xxx.xxx:3001

英文:

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

huangapple
  • 本文由 发表于 2023年2月18日 08:05:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75490289.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定