diff --git a/src/index.ts b/src/index.ts index d60da14..b86bf37 100644 --- a/src/index.ts +++ b/src/index.ts @@ -67,6 +67,10 @@ Sentry.init({ environment: config.global.debug ? 'development' : 'production' }); +app.locals.versionRev = require('child_process') +.execSync('git rev-parse --short HEAD') +.toString().trim() + // RequestHandler creates a separate execution context using domains, so that every // transaction/span/breadcrumb is attached to its own Hub instance app.use(Sentry.Handlers.requestHandler()); diff --git a/src/routes/api/v1/version.ts b/src/routes/api/v1/version.ts index 4e75092..52b285b 100644 --- a/src/routes/api/v1/version.ts +++ b/src/routes/api/v1/version.ts @@ -1,9 +1,7 @@ import express, { Request, Response } from 'express'; function get(req: Request, res: Response) { - const revision = require('child_process') - .execSync('git rev-parse --short HEAD') - .toString().trim() + const revision = req.app.locals.versionRev; res.status(200).send({ version: '1.0.0', commit: revision }); };