Skip to content

Commit eaa348f

Browse files
committed
Expose server version via /version endpoint
1 parent 92dda40 commit eaa348f

4 files changed

Lines changed: 22 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
platforms: linux/amd64,linux/arm64
6666
tags: ${{ steps.meta.outputs.tags }}
6767
labels: ${{ steps.meta.outputs.labels }}
68-
build-args: VERSION=${{ github.sha }}
68+
build-args: GIT_HASH=${{ github.sha }}
6969

7070
- name: Extract sha-* image label
7171
id: extract-sha

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ RUN npm ci --omit=dev
1111

1212
COPY src/ src/
1313

14+
ARG GIT_HASH
15+
ENV VERSION_HASH=${GIT_HASH}
1416
CMD ["npm", "start"]

src/endpoints/http-index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ export * from './http/json.js';
3535
export * from './http/trailers.js';
3636
export * from './http/error/close.js';
3737
export * from './http/error/reset.js';
38-
export * from './http/example-page.js';
38+
export * from './http/example-page.js';
39+
export * from './http/version.js';

src/endpoints/http/version.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { HttpEndpoint, HttpHandler } from '../http-index.js';
2+
3+
const versionHash = process.env.VERSION_HASH || 'unknown';
4+
5+
const matchPath = (path: string) => path === '/version';
6+
7+
const handle: HttpHandler = (_req, res) => {
8+
res.writeHead(200, { 'content-type': 'application/json' });
9+
res.end(JSON.stringify({
10+
versionHash
11+
}));
12+
}
13+
14+
export const versionJson: HttpEndpoint = {
15+
matchPath,
16+
handle
17+
};

0 commit comments

Comments
 (0)