Skip to content

Commit ab5c6ab

Browse files
authored
Merge pull request #36 from NebulaServices/commitinfo
Add commit info to the INFO endpoint
2 parents 33a8935 + abfdb1f commit ab5c6ab

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
dist
33
.DS_Store
4-
**/.DS_Store
4+
**/.DS_Store
5+
package-lock.json

index.js

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

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

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

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

1928
const bare = createBareServer('/bare/');
2029
const serverFactory = (handler, opts) => {
2130
return createServer()
2231
.on("request", (req, res) => {
23-
if (req.url === "/version") {
24-
const versionResponse = {
25-
version: _v,
26-
};
32+
if (req.url === "/info") {
2733
res.writeHead(200, { 'Content-Type': 'application/json' });
28-
res.end(JSON.stringify(versionResponse));
34+
res.end(JSON.stringify(info));
2935
} else if (bare.shouldRoute(req)) {
3036
bare.routeRequest(req, res);
3137
} else {

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"start": "node --max-http-header-size=50000 index",
88
"build:dev": "node esbuild.dev.js",
99
"build:prod": "node esbuild.prod.js",
10-
"build": "node esbuild.prod.js"
10+
"build": "node esbuild.prod.js",
11+
"webpack": "echo 'Webpack building is no longer a supported build utility.'"
1112
},
1213
"keywords": [],
1314
"author": "",
@@ -27,6 +28,7 @@
2728
"domhandler": "^5.0.3",
2829
"esbuild": "^0.19.0",
2930
"fastify": "^4.21.0",
31+
"git-commit-info": "^2.0.2",
3032
"idb": "^7.0.2",
3133
"open": "^9.1.0",
3234
"parse5": "^7.1.2",

static/resources/scripts/settings.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,22 @@ class Modal {
9090
new Modal();
9191

9292
window.addEventListener('DOMContentLoaded', function (){
93-
console.log('buh')
93+
9494
const versionInd = document.getElementById('settings-version')
9595
const xhr = new XMLHttpRequest();
96-
xhr.open("GET", '/version');
96+
xhr.open("GET", '/info');
9797
xhr.send();
9898
xhr.responseType = "json";
9999
xhr.onload = () => {
100100
if (xhr.readyState == 4 && xhr.status == 200) {
101-
console.log(xhr.response)
102-
versionInd.innerText = `Dynamic v${xhr.response.version}`
101+
const response = xhr.response;
102+
versionInd.innerHTML = `Dynamic v${response.version} <span id='hashHover'> (${response.hashShort}) </span> `
103+
const hashHover = document.getElementById('hashHover')
104+
hashHover.onclick = function displayFullHash(){
105+
console.log('cool')
106+
hashHover.innerText = `(${response.hash})`
107+
hashHover.style.fontSize = `10px`
108+
}
103109
} else {
104110
versionInd.innerText = 'Unable to get version'
105111
}

0 commit comments

Comments
 (0)