Skip to content

Commit f882232

Browse files
committed
Added BIND_ADDRESS environment variable
1 parent b1e3149 commit f882232

File tree

6 files changed

+14
-1
lines changed

6 files changed

+14
-1
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
PORT=3000
2+
BIND_ADDRESS=0.0.0.0
23
FRACTAL_SERVER_URL=http://localhost:8000
34
VIZARR_STATIC_FILES_PATH=/path/to/vizarr/dist
45
BASE_PATH=/vizarr

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Note: Numbers like (#123) point to closed Pull Requests on the fractal-vizarr-viewer repository.
22

3+
# Unreleased
4+
5+
* Added `BIND_ADDRESS` environment variable, defaulting to `0.0.0.0` for IPv4 binding (\#64);
6+
37
# 0.3.2
48

59
* Updated vizarr git commit references to include labels feature;

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ To start the application installed in this way see the section [Run fractal-viza
6464
## Environment variables
6565

6666
* `PORT`: the port where fractal-vizarr-viewer app is served;
67+
* `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`;
6768
* `FRACTAL_SERVER_URL`: the base URL of fractal-server;
6869
* `VIZARR_STATIC_FILES_PATH`: path to the files generated running `npm run build` in vizarr source folder;
6970
* `BASE_PATH`: base path of fractal-vizarr-viewer application;
@@ -84,6 +85,7 @@ You can create a script with the following content to run fractal-vizarr-viewer
8485
#!/bin/sh
8586

8687
export PORT=3000
88+
export BIND_ADDRESS=0.0.0.0
8789
export FRACTAL_SERVER_URL=http://localhost:8000
8890
export VIZARR_STATIC_FILES_PATH=/path/to/vizarr/dist
8991
export AUTHORIZATION_SCHEME=fractal-server
@@ -145,6 +147,7 @@ After=syslog.target
145147
[Service]
146148
User=fractal
147149
Environment="PORT=3000"
150+
Environment="BIND_ADDRESS=0.0.0.0"
148151
Environment="FRACTAL_SERVER_URL=https://fractal-server.example.com/"
149152
Environment="VIZARR_STATIC_FILES_PATH=/path/to/vizarr/dist"
150153
Environment="BASE_PATH=/vizarr"

src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ app.use(`${config.basePath}alive`, async function (req, res) {
3333
app.use(`${config.basePath}`, express.static(config.vizarrStaticFilesPath));
3434

3535
// Start server
36-
const server = app.listen(config.port, () => {
36+
const server = app.listen(config.port, config.bindAddress, () => {
3737
logger.info(
3838
"fractal-vizarr-viewer is listening at http://localhost:%d%s",
3939
config.port,

src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function getRequiredEnv(envName: string) {
2424
*/
2525
function loadConfig(): Config {
2626
const port = process.env.PORT ? parseInt(process.env.PORT) : 3000;
27+
const bindAddress = process.env.BIND_ADDRESS || "0.0.0.0";
2728
const fractalServerUrl = getRequiredEnv("FRACTAL_SERVER_URL");
2829
const vizarrStaticFilesPath = getRequiredEnv("VIZARR_STATIC_FILES_PATH");
2930

@@ -59,6 +60,8 @@ function loadConfig(): Config {
5960
basePath += "/";
6061
}
6162

63+
logger.debug("PORT: %s", port);
64+
logger.debug("BIND_ADDRESS: %s", bindAddress);
6265
logger.debug("FRACTAL_SERVER_URL: %s", fractalServerUrl);
6366
logger.debug("BASE_PATH: %s", basePath);
6467
logger.debug("VIZARR_STATIC_FILES_PATH: %s", vizarrStaticFilesPath);
@@ -67,6 +70,7 @@ function loadConfig(): Config {
6770

6871
return {
6972
port,
73+
bindAddress,
7074
fractalServerUrl,
7175
basePath,
7276
vizarrStaticFilesPath,

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type AuthorizationScheme =
55

66
export type Config = {
77
port: number;
8+
bindAddress: string;
89
fractalServerUrl: string;
910
basePath: string;
1011
vizarrStaticFilesPath: string;

0 commit comments

Comments
 (0)