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

Added alive endpoint #55

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
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