英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论