NestJS allow distributed tracing headers

I would like to implement distributed tracing (using Elastic/Kibana)

For the stack, I am using NestJS 8 and Node 16 for the backend + NextJS 12 and Node 14 for the frontend

I would like to enable CORS on NestJS running GraphQL/Apollo server

In a simple Express application, this is how I configured for CORS and it worked fine

 app.use(function (request, response, next) {
    response.setHeader('Access-Control-Allow-Headers', ['traceparent', 'tracestate']);
    response.setHeader('Access-Control-Request-Method', ['request-method']);
    response.setHeader('Origin', ['request-origin']);
    return next();
  });

But in Apollo server, there is a different way of configuring CORS headers:

  app.enableCors({
    origin: <my origin URL>,
  });

I am curious if there is a way to configure the response headers using the app.enableCors method or is there an alternative way that will work for Apollo/NestJS?

Leave a Comment