Skip to content

Commit

Permalink
Merge pull request #55 from fractal-analytics-platform/alive-endpoint
Browse files Browse the repository at this point in the history
Added alive endpoint
  • Loading branch information
tcompa authored Jan 7, 2025
2 parents f2de585 + c4737ea commit a70f3d1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Note: Numbers like (#123) point to closed Pull Requests on the fractal-vizarr-viewer repository.

# Unreleased

* Added `/alive` endpoint (\#55);

# 0.3.0

* Retrieved complete list of allowed viewer paths directly from fractal-server: (\#53);
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ The output is located in the `dist` folder.

Then go back to fractal-vizarr-viewer folder and run `npm run start` to start the project. The server will start on port 3000.

### Alive endpoint

It is possible to use the `/alive` endpoint to check if the service is up and running and retrieve its version.

## Docker setup

The following script can be used to build and start a docker image for testing:
Expand Down
31 changes: 18 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions src/alive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Request, Response } from "express";
import { createRequire } from "module";
import { getConfig } from "./config.js";
import { getLogger } from "./logger.js";

const config = getConfig();
const logger = getLogger();

export async function aliveEndpoint(_: Request, res: Response) {

// reading version from package.json
const require = createRequire(import.meta.url);
const { version } = require("../package.json");

// retrieving server status
let fractal_server_alive = false;
let fractal_server_version: string | null = null;

try {
const response = await fetch(`${config.fractalServerUrl}/api/alive/`);
if (response.ok) {
const { alive, version } = await response.json();
fractal_server_alive = alive;
fractal_server_version = version;
}
} catch {
logger.error("Error reading fractal-server alive endpoint");
}

res.json({ alive: true, version, fractal_server_alive, fractal_server_version }).end();
}
6 changes: 6 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getLogger } from "./logger.js";
import { getConfig } from "./config.js";
import { serveZarrData } from "./data.js";
import { getAuthorizer } from "./authorizer.js";
import { aliveEndpoint } from "./alive.js";

const config = getConfig();
const logger = getLogger();
Expand All @@ -23,6 +24,11 @@ app.use(`${config.basePath}data`, async function (req, res) {
await serveZarrData(authorizer, req, res);
});

// Alive endpoint
app.use(`${config.basePath}alive`, async function (req, res) {
await aliveEndpoint(req, res);
});

// Serving Vizarr static files
app.use(`${config.basePath}`, express.static(config.vizarrStaticFilesPath));

Expand Down

0 comments on commit a70f3d1

Please sign in to comment.