Skip to content

Commit

Permalink
Make messages endpoint configurable via env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
tillprochaska committed Jul 29, 2022
1 parent 8862d4c commit 02c07e1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
1 change: 1 addition & 0 deletions aleph/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

# Show a system-wide banner in the user interface.
APP_BANNER = env.get("ALEPH_APP_BANNER")
APP_MESSAGES_URL = env.get("ALEPH_APP_MESSAGES_URL", None)

# Force HTTPS here:
FORCE_HTTPS = True if APP_UI_URL.lower().startswith("https") else False
Expand Down
1 change: 1 addition & 0 deletions aleph/views/base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def _metadata_locale(locale):
"version": __version__,
"banner": settings.APP_BANNER,
"ui_uri": settings.APP_UI_URL,
"messages_url": settings.APP_MESSAGES_URL,
"publish": archive.can_publish,
"logo": app_logo,
"favicon": settings.APP_FAVICON,
Expand Down
7 changes: 2 additions & 5 deletions ui/src/actions/messagesActions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import axios from 'axios';
import asyncActionCreator from 'actions/asyncActionCreator';

const MESSAGES_ENDPOINT =
'https://tillprochaska.github.io/status-page-workflow/messages.json';

export const fetchMessages = asyncActionCreator(
() => async () => {
const response = await axios.get(MESSAGES_ENDPOINT);
(endpoint) => async () => {
const response = await axios.get(endpoint);
return { messages: response.data };
},
{ name: 'FETCH_MESSAGES' }
Expand Down
33 changes: 22 additions & 11 deletions ui/src/app/Router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,15 @@ const MESSAGES_INTERVAL = 15 * 60 * 1000; // every 15 minutes
class Router extends Component {
componentDidMount() {
this.fetchIfNeeded();

this.setState(() => ({
messagesInterval: setInterval(
() => this.props.fetchMessages(),
MESSAGES_INTERVAL
),
}));
this.setMessagesInterval();
}

componentDidUpdate() {
this.fetchIfNeeded();
}

componentWillUnmount() {
if (this.state?.messagesInterval) {
clearInterval(this.state.messagesInterval);
}
this.clearMessagesInterval();
}

fetchIfNeeded() {
Expand All @@ -72,7 +64,26 @@ class Router extends Component {
}

if (messages.shouldLoad) {
this.props.fetchMessages();
this.fetchMessages();
}
}

fetchMessages() {
const { metadata } = this.props;

if (metadata?.app?.messages_url) {
this.props.fetchMessages(metadata.app.messages_url);
}
}

setMessagesInterval() {
const id = setInterval(() => this.fetchMessages(), MESSAGES_INTERVAL);
this.setState(() => ({ messagesInterval: id }));
}

clearMessagesInterval() {
if (this.state?.messagesInterval) {
clearInterval(this.state.messagesInterval);
}
}

Expand Down

0 comments on commit 02c07e1

Please sign in to comment.