Skip to content

Commit 78a6d0e

Browse files
committed
Version endpoint updated to include commit hash
1 parent f00eacd commit 78a6d0e

File tree

4 files changed

+492
-9
lines changed

4 files changed

+492
-9
lines changed

index.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,30 @@ import open from 'open';
77
import { existsSync } from 'fs';
88
import { join, dirname } from 'path';
99
import { fileURLToPath } from 'url';
10+
import { createRequire } from 'module';
11+
const require = createRequire(import.meta.url);
12+
const gitCommitInfo = require('git-commit-info');
13+
1014

1115
if (!existsSync("./dist")) await import("./esbuild.prod.js");
1216

1317
const __dirname = dirname(fileURLToPath(import.meta.url));
1418

1519
const port = process.env.PORT || 3000;
1620
const _v = process.env.npm_package_version;
21+
const info = {
22+
hashShort: `${JSON.stringify(gitCommitInfo().shortHash).replace('"', "").replace("/", "").replace('\"', "")}`,
23+
hash: `${JSON.stringify(gitCommitInfo().hash).replace('"', "").replace("/", "").replace('\"', "")}`,
24+
version: _v,
25+
}
1726

1827
const bare = createBareServer('/bare/');
1928
const serverFactory = (handler, opts) => {
2029
return createServer()
2130
.on("request", (req, res) => {
22-
if (req.url === "/version") {
23-
const versionResponse = {
24-
version: _v,
25-
};
31+
if (req.url === "/info") {
2632
res.writeHead(200, { 'Content-Type': 'application/json' });
27-
res.end(JSON.stringify(versionResponse));
33+
res.end(JSON.stringify(info));
2834
} else if (bare.shouldRoute(req)) {
2935
bare.routeRequest(req, res);
3036
} else {

0 commit comments

Comments
 (0)