vendure icon indicating copy to clipboard operation
vendure copied to clipboard

Expose httpAdapter options

Open hendrik-advantitge opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe. We would like to configure Sentry as an application monitoring tool in Vendure. In an Express environment, it should be configured as middleware using

const app = express()
app.use(Sentry.Handlers.requestHandler())
app.use(Sentry.Handlers.tracingHandler())

In Vendure we currently have no access to this object.

Describe the solution you'd like We would like to define an httpAdapter in the config settings for both the server and the worker. For example:

-    const { hostname, port, cors, middleware } = config.apiOptions;
+    const { hostname, port, cors, middleware, serverHttpAdapter } = config.apiOptions;
     default_logger_1.DefaultLogger.hideNestBoostrapLogs();
-    const app = await core_1.NestFactory.create(appModule.AppModule, {
+    const app = await core_1.NestFactory.create(appModule.AppModule, serverHttpAdapter, {
         cors,
         logger: new vendure_logger_1.Logger(),
     });

Describe alternatives you've considered Currently we do this using a patch on Vendure core

hendrik-advantitge avatar Sep 12 '22 14:09 hendrik-advantitge

Is it not possible to get the httpAdapter post-bootstrap and call the middleware there?

const app = await bootstrap(config);
app.use(Sentry.Handlers.requestHandler());

// or (i think this might be doing the same thing?)
app.getHttpAdapter().use(Sentry.Handlers.requestHandler()); 

I've not tested this, and maybe you aren't allowed to call .use() after the server started listening, but just thought it is worth checking before we proceed.

michaelbromley avatar Sep 14 '22 14:09 michaelbromley

Hi Michael, I think that would work but then you are not able to put the Sentry logic inside a plugin? Maybe I'm missing something obvious.

hendrik-advantitge avatar Sep 15 '22 13:09 hendrik-advantitge

For a plugin I think you could inject HttpAdapterHost and access the underlying express app that way - not tried this but if so, I'd say this issue should be to add some documentation about that.

michaelbromley avatar Sep 15 '22 18:09 michaelbromley

That seems to work. We can inject HttpAdapterHost in the plugin and initialise Sentry OnApplicationBootstrap. The Sentry documentation tells us Sentry should be the first middleware, I'm not sure that is the case when we add it OnApplicationBootstrap. For now it does not seem to cause any issues

hendrik-advantitge avatar Sep 16 '22 08:09 hendrik-advantitge