Skip to content

Commit 31a5c06

Browse files
committed
Added support for displaying temporary warning banner
1 parent 7cfe289 commit 31a5c06

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ LOG_LEVEL_FILE=info
1919
LOG_LEVEL_CONSOLE=warn
2020

2121
FRACTAL_API_V1_MODE=include
22+
#WARNING_BANNER_PATH=/path/to/banner.txt

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ LOG_LEVEL_FILE=debug
1818
LOG_LEVEL_CONSOLE=info
1919

2020
FRACTAL_API_V1_MODE=include
21+
#WARNING_BANNER_PATH=/path/to/banner.txt

docs/environment-variables.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ The following environment variables can be used to configure fractal-web.
1717
* `LOG_LEVEL_FILE`: the log level of logs that will be written to the file; the default value is `info`;
1818
* `LOG_LEVEL_CONSOLE`: the log level of logs that will be written to the console; the default value is `warn`;
1919
* `FRACTAL_API_V1_MODE`: include/exclude V1 pages and version switcher; the default value is `include`;
20-
* `PUBLIC_FRACTAL_VIZARR_VIEWER_URL`: URL to [fractal-vizarr-viewer](https://github.com/fractal-analytics-platform/fractal-vizarr-viewer) service (e.g. http://localhost:3000/vizarr for testing).
20+
* `PUBLIC_FRACTAL_VIZARR_VIEWER_URL`: URL to [fractal-vizarr-viewer](https://github.com/fractal-analytics-platform/fractal-vizarr-viewer) service (e.g. http://localhost:3000/vizarr for testing);
21+
* `WARNING_BANNER_PATH`: specifies the path to a text file containing the warning banner message displayed on the site; the banner is used to inform users about important issues, such as external resources downtime or maintenance alerts; if the variable is empty or unset no banner is displayed.
2122

2223
When running directly using `node` command these extra variables can also be configured:
2324

docs/quickstart.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export LOG_FILE=fractal-web.log
5757

5858
export FRACTAL_API_V1_MODE=include
5959

60+
#export PUBLIC_FRACTAL_VIZARR_VIEWER_URL=
61+
#export WARNING_BANNER_PATH=
62+
6063
# default values are usually fine for the following variables; remove comments if needed
6164
#export AUTH_COOKIE_NAME=fastapiusersauth
6265
#export AUTH_COOKIE_PATH=/

src/routes/+layout.server.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { env } from '$env/dynamic/private';
22
import { getLogger } from '$lib/server/logger.js';
3+
import fs from 'fs/promises';
34

45
const logger = getLogger('page layout');
56

@@ -16,8 +17,24 @@ export async function load({ locals, request, url }) {
1617
logger.error('pageInfo is missing, it should have been loaded by hooks.server.js');
1718
}
1819

20+
const warningBanner = await getWarningBanner();
21+
1922
return {
2023
...pageInfo,
24+
warningBanner,
2125
v1Enabled: env.FRACTAL_API_V1_MODE !== 'exclude'
2226
};
2327
}
28+
29+
async function getWarningBanner() {
30+
if (!env.WARNING_BANNER_PATH) {
31+
return null;
32+
}
33+
try {
34+
const bannerData = await fs.readFile(env.WARNING_BANNER_PATH, { encoding: 'utf-8' });
35+
return bannerData.trim();
36+
} catch (err) {
37+
logger.error('An error happened reading warning banner file %s', env.WARNING_BANNER_PATH, err);
38+
return null;
39+
}
40+
}

src/routes/+layout.svelte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
$: server = $page.data.serverInfo || {};
1212
/** @type {'v1'|'v2'} */
1313
$: apiVersion = $page.url.pathname.startsWith('/v1') ? 'v1' : 'v2';
14+
$: warningBanner = $page.data.warningBanner;
1415
// @ts-ignore
1516
// eslint-disable-next-line no-undef
1617
let clientVersion = __APP_VERSION__;
@@ -220,6 +221,16 @@
220221
Sorry, we are performing some maintenance on fractal-server. It will be back online soon.
221222
</div>
222223
{/if}
224+
{#if warningBanner}
225+
<div class="alert alert-warning">
226+
{#each warningBanner.split('\n') as line, index}
227+
{#if index > 0}
228+
<br />
229+
{/if}
230+
{line}
231+
{/each}
232+
</div>
233+
{/if}
223234
{#if userLoggedIn && !$page.data.userInfo.is_verified}
224235
<div class="row">
225236
<div class="col">

0 commit comments

Comments
 (0)