Skip to content

Commit

Permalink
Add /version endpoint (#15)
Browse files Browse the repository at this point in the history
* Add `/version` endpoint

Provide API version and commit hash.

* Update README for new endpoint

Closes #13
  • Loading branch information
0237h committed Apr 24, 2024
1 parent 859edeb commit 3f3fb77
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
| GET <br>`text/plain` | `/health` | Performs health checks and checks if the database is accessible |
| GET <br>`text/plain` | `/metrics` | [Prometheus](https://prometheus.io/) metrics |
| GET <br>`application/json` | `/openapi` | [OpenAPI](https://www.openapis.org/) specification |
| GET <br>`application/json` | `/version` | API version and commit hash |

## Requirements

Expand Down
3 changes: 3 additions & 0 deletions src/fetch/GET.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { logger } from "../logger.js";
import swaggerHtml from "../../swagger/index.html"
import swaggerFavicon from "../../swagger/favicon.png"
import transfers from "./transfers.js";
import { toJSON } from "./utils.js";
import { APP_VERSION } from "../config.js";

export default async function (req: Request) {
const { pathname } = new URL(req.url);
Expand All @@ -21,6 +23,7 @@ export default async function (req: Request) {
if (pathname === "/health") return health(req);
if (pathname === "/metrics") return new Response(await registry.metrics(), { headers: { "Content-Type": registry.contentType } });
if (pathname === "/openapi") return new Response(openapi, { headers: { "Content-Type": "application/json" } });
if (pathname === "/version") return toJSON({ version: APP_VERSION.split('+')[0], commit: APP_VERSION.split('+')[1] });

// Token endpoints
if (pathname === "/supply") return supply(req);
Expand Down
9 changes: 8 additions & 1 deletion src/fetch/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,14 @@ export default new OpenApiBuilder()
get: {
tags: [TAGS.DOCS],
summary: "OpenAPI JSON specification",
responses: { 200: { description: "OpenAPI JSON specification", content: { "application/json": { schema: { type: "string" } } } } },
responses: { 200: { description: "OpenAPI JSON specification", content: { "application/json": {} } } },
},
})
.addPath("/version", {
get: {
tags: [TAGS.DOCS],
summary: "API version",
responses: { 200: { description: "API version and commit hash", content: { "application/json": {} } } },
},
})
.getSpecAsJson();

0 comments on commit 3f3fb77

Please sign in to comment.