Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commit info to the INFO endpoint #36

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
.DS_Store
**/.DS_Store
**/.DS_Store
package-lock.json
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@ import open from 'open';
import { existsSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const gitCommitInfo = require('git-commit-info');


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

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

const port = process.env.PORT || 3000;
const _v = process.env.npm_package_version;
const info = {
hashShort: `${JSON.stringify(gitCommitInfo().shortHash).replace('"', "").replace("/", "").replace('\"', "")}`,
hash: `${JSON.stringify(gitCommitInfo().hash).replace('"', "").replace("/", "").replace('\"', "")}`,
version: _v,
}

const bare = createBareServer('/bare/');
const serverFactory = (handler, opts) => {
return createServer()
.on("request", (req, res) => {
if (req.url === "/version") {
const versionResponse = {
version: _v,
};
if (req.url === "/info") {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(versionResponse));
res.end(JSON.stringify(info));
} else if (bare.shouldRoute(req)) {
bare.routeRequest(req, res);
} else {
Expand Down
Loading