0

I Use NestJs as a backend server and angular as a frontend it's okay with me when I use chrome on pc and I can do all my requests but when I use my android chrome with DevTools I receive this error

message: "Http failure response for http://localhost:3000/users/login: 0 Unknown Error"

here is a snapshot of the error message enter image description here

it also send the same error with pc chrome if i didnt open CORS on NestJs

here Is My COSR Config

import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { NextFunction, Request, Response } from 'express';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.use((req: Request, res: Response, next: NextFunction) => {
    console.log(req);
    next();
  });
  app.useGlobalPipes(new ValidationPipe());
  app.enableCors({
    origin: true,
    methods: ['GET', 'PUT', 'POST', 'DELETE'],
    exposedHeaders: ['x-auth'],
  });
  await app.listen(3000);
}
bootstrap();

by the way when I log the request on my nest app I didn't receive any request I think NestJsrefused it immediately

Kamal Radwan
  • 47
  • 1
  • 1
  • 8
  • Does this answer your question? [NestJS enable cors in production](https://stackoverflow.com/questions/50949231/nestjs-enable-cors-in-production) – O. Jones Aug 08 '21 at 11:45

1 Answers1

0

I found Where is the problem I was using the localhost as a Backend IP and the application was connecting on my local pc Backend and that was the problem

I solved this by editing the Backend IP to the production IP and finally, everything works good ,, Thanks All

Kamal Radwan
  • 47
  • 1
  • 1
  • 8