I created an api using NestJs and GraphQL, exposing a GraphQL server (Apollo) with a certain port.
Everything works fine as long as I am using http://localhost:3001/graphql
endpoint. As soon as I change to http://<ip-address>:3001/graphql
the connection cannot be established.
I modified main.ts
file to include the host adress as well, and I was expecting to be able to reach the endpoint withing the same machine, but in vain.
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors();
await app.listen(3001, '0.0.0.0', async () => {
console.log(` Server started at ${await app.getUrl()}`);
});
}
bootstrap();
Dependencies:
"@nestjs/graphql": "^10.2.0",
"graphql": "^16.6.0",
"@nestjs/apollo": "^10.2.0",