improve /version api route to only call git once on startup

This commit is contained in:
Sören Oesterwind 2023-07-10 15:09:30 +02:00
parent 45a4935190
commit a79a1eab81
2 changed files with 5 additions and 3 deletions

View File

@ -67,6 +67,10 @@ Sentry.init({
environment: config.global.debug ? 'development' : 'production' 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 // RequestHandler creates a separate execution context using domains, so that every
// transaction/span/breadcrumb is attached to its own Hub instance // transaction/span/breadcrumb is attached to its own Hub instance
app.use(Sentry.Handlers.requestHandler()); app.use(Sentry.Handlers.requestHandler());

View File

@ -1,9 +1,7 @@
import express, { Request, Response } from 'express'; import express, { Request, Response } from 'express';
function get(req: Request, res: Response) { function get(req: Request, res: Response) {
const revision = require('child_process') const revision = req.app.locals.versionRev;
.execSync('git rev-parse --short HEAD')
.toString().trim()
res.status(200).send({ version: '1.0.0', commit: revision }); res.status(200).send({ version: '1.0.0', commit: revision });
}; };