Skip to content

Commit

Permalink
Merge pull request #29 from EjembiEmmanuel/main
Browse files Browse the repository at this point in the history
fix: fix qraphql CORS error
  • Loading branch information
Oshioke-Salaki authored Feb 21, 2025
2 parents a95a180 + 978d5d3 commit e0c89ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ import { PrismaModule } from './prisma/prisma.module';
import { SharedIndexerModule } from './shared-indexer/shared-indexer.module';
import { TokenGiverIndexerModule } from './token-giver-indexer/token-giver-indexer.module';
import { ResolversModule } from './resolvers/resolvers.module';

@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
autoSchemaFile: true,
resolvers: { JSON: GraphQLJSON },
csrfPrevention: {
requestHeaders: [
'Accept',
'Authorization',
'Content-Type',
'X-Requested-With',
'apollo-require-preflight',
],
},
}),
PrismaModule,
SharedIndexerModule,
Expand Down
13 changes: 5 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';

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

const corsOptions: CorsOptions = {
app.enableCors({
origin: '*',
methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE', 'OPTIONS'],
credentials: true,
allowedHeaders: [
'Accept',
'Authorization',
'Content-Type',
'X-Requested-With',
'Authorization',
'x-apollo-operation-name',
'apollo-require-preflight',
],
credentials: true,
};
methods: ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS'],
});

app.enableCors(corsOptions);
await app.listen(process.env.PORT ?? 3000);
}
bootstrap();

0 comments on commit e0c89ce

Please sign in to comment.