Skip to content

Commit 68d8094

Browse files
authored
Merge pull request #66 from fractal-analytics-platform/vizarr-optional-endpoint
Made VIZARR_STATIC_FILES_PATH environment variable optional
2 parents 3ce98db + c38ce84 commit 68d8094

File tree

7 files changed

+33
-2
lines changed

7 files changed

+33
-2
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ PORT=3000
22
BIND_ADDRESS=0.0.0.0
33
FRACTAL_SERVER_URL=http://localhost:8000
44
BASE_PATH=/data
5+
VIZARR_STATIC_FILES_PATH=/path/to/vizarr/dist
56
AUTHORIZATION_SCHEME=fractal-server
67
CACHE_EXPIRATION_TIME=60

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Note: Numbers like (#123) point to closed Pull Requests on the fractal-vizarr-vi
44

55
* Separated fractal-data from vizarr, renamed repository to `fractal-data` (\#64);
66
* Added `BIND_ADDRESS` environment variable, defaulting to `0.0.0.0` for IPv4 binding (\#64);
7+
* Made `VIZARR_STATIC_FILES_PATH` environment variable optional (\#66);
78

89
# 0.3.2
910

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
FROM node:20
22

3+
WORKDIR /
4+
5+
RUN git clone https://github.com/hms-dbmi/vizarr.git
6+
WORKDIR /vizarr
7+
8+
RUN git checkout eb2b77fed92a08c78c5770144bc7ccf19e9c7658
9+
RUN npx -y pnpm install
10+
RUN npx pnpm run build
11+
312
RUN mkdir /fractal-data
413

514
WORKDIR /fractal-data
@@ -11,4 +20,6 @@ ADD tsconfig.json .
1120
RUN npm install
1221
RUN npm run build
1322

23+
ENV VIZARR_STATIC_FILES_PATH=/vizarr/dist
24+
1425
CMD ["node", "/fractal-data/dist/app.js"]

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ Prototype to explore serving/viewing zarr data.
44

55
This repository contains a simple server application made using [Express](https://expressjs.com/).
66

7-
The application has 2 endpoints:
7+
The application has 3 endpoints:
88

99
- the endpoint `/files/{path-to-zarr}`, that serves the content of Zarr files checking user authorization.
1010
- the endpoint `/alive`, that returns the status of the service.
11+
- the optional endpoint `/vizarr`, that serves vizarr static files when the `VIZARR_STATIC_FILES_PATH` environment variable is set.
1112

1213
> To run fractal-data you need to have an active instance of `fractal-server` and an active instance of `fractal-web`. You need to log-in to `fractal-web` from the browser using a user that has been authorized to see the vizarr files. Details about authorization are explained in the next section.
1314
@@ -72,6 +73,7 @@ To start the application installed in this way see the section [Run fractal-data
7273
- `PORT`: the port where fractal-data app is served;
7374
- `BIND_ADDRESS`: specifies the IP address for the server to bind to; use `0.0.0.0` (IPv4) or `::` (IPv6) to listen on all interfaces, `127.0.0.1` (IPv4) or `::1` (IPv6) for localhost only; the default value is `0.0.0.0`;
7475
- `FRACTAL_SERVER_URL`: the base URL of fractal-server;
76+
- `VIZARR_STATIC_FILES_PATH`: path to the files generated running `npm run build` in Vizarr source folder; this variable is optional and, if present, it will be used to serve Vizarr static files from the `/vizarr` endpoint;
7577
- `BASE_PATH`: base path of fractal-data application;
7678
- `AUTHORIZATION_SCHEME`: defines how the service verifies user authorization. The following options are available:
7779
- `fractal-server`: the paths that can be accessed by each user are retrieved calling fractal-server API.
@@ -205,7 +207,7 @@ The output is located in the `dist` folder.
205207

206208
### Run fractal-data
207209

208-
Then go back to fractal-data folder and run `npm run start` to start the project. The server will start on port 3000.
210+
Then go back to fractal-data folder and run `npm run start` to start the project. The server will start on port 3000. Remember to set the `VIZARR_STATIC_FILES_PATH`, to serve Vizarr static files from the `/vizarr` endpoint. Vizarr static files need to be served from the same port and domain of the fractal-data service, otherwise you will encounter CORS issues.
209211

210212
### Alive endpoint
211213

src/app.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ app.use(`${config.basePath}alive`, async function (req, res) {
2929
await aliveEndpoint(req, res);
3030
});
3131

32+
// Serving Vizarr static files
33+
if (config.vizarrStaticFilesPath) {
34+
app.use(
35+
`${config.basePath}vizarr`,
36+
express.static(config.vizarrStaticFilesPath)
37+
);
38+
}
39+
3240
// Start server
3341
const server = app.listen(config.port, config.bindAddress, () => {
3442
logger.info(

src/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,19 @@ function loadConfig(): Config {
5959
basePath += "/";
6060
}
6161

62+
const vizarrStaticFilesPath = process.env.VIZARR_STATIC_FILES_PATH;
63+
6264
logger.debug("PORT: %s", port);
6365
logger.debug("BIND_ADDRESS: %s", bindAddress);
6466
logger.debug("FRACTAL_SERVER_URL: %s", fractalServerUrl);
6567
logger.debug("BASE_PATH: %s", basePath);
6668
logger.debug("AUTHORIZATION_SCHEME: %s", authorizationScheme);
6769
logger.debug("CACHE_EXPIRATION_TIME: %d", cacheExpirationTime);
6870

71+
if (vizarrStaticFilesPath) {
72+
logger.debug("VIZARR_STATIC_FILES_PATH: %s", vizarrStaticFilesPath);
73+
}
74+
6975
return {
7076
port,
7177
bindAddress,
@@ -75,6 +81,7 @@ function loadConfig(): Config {
7581
cacheExpirationTime,
7682
testingUsername,
7783
testingPassword,
84+
vizarrStaticFilesPath,
7885
};
7986
}
8087

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type Config = {
1212
cacheExpirationTime: number;
1313
testingUsername: string | null;
1414
testingPassword: string | null;
15+
vizarrStaticFilesPath: string | undefined;
1516
};
1617

1718
export type User = {

0 commit comments

Comments
 (0)