Skip to content
Permalink
Browse files

Merge branch 'server-address'

* server-address:
  Fix bugs & document "serverAddress" customisation
  • Loading branch information
jameshadfield committed Nov 15, 2019
2 parents 0bc5ed1 + 4a822a8 commit 8e97d6f9168e1c0f9fd28379d6be671313bbe854
@@ -27,7 +27,7 @@ A useful reference may be the [customisation JSON file](https://github.com/nexts
* `navbarComponent` a (relative) path to a JS file exporting a React component to be rendered as the nav bar. See below.
* `browserTitle` The browser title for the page. Defaults to "auspice" if not defined.
* `googleAnalyticsKey` You can specify a Google Analytics key to enable (some) analytics functionality. More documentation to come.

* `serverAddress` Specify the address / prefix which the auspice client uses for API requests.

> For customisation code which uses [React](https://reactjs.org/) components, you must import these as `import React from "@libraries/react";` to ensure that the version of react is the same as what Auspice uses.
@@ -118,3 +118,13 @@ Where the javascript file contains a default export of a React component.
| `errorMessage` | function | to do |
| `changePage` | function | to do |

---

## Specifying the API server address

By default, the client makes API requests ([as detailed here](requests.md)) to "/charon/getAvailable", "/charon/getDataset" etc.
This is using the default server address of "/charon".
This can be changed by specifying `serverAddress` in the customisation JSON.

> Note that currently you can't specify a different domain due to CORS headers.
This may well be a simple fix -- please get in touch if you can help here!
@@ -24,7 +24,7 @@ When a dataset, narrative, or listing of available datasets is to be displayed i
* `/charon/getDataset` -- return the requested dataset
* `/charon/getNarrative` -- return the requested narrative

See [the server API documentation](server/api.md) for more details.
See [the server API documentation](server/api.md) for more details about the requests, or the [client customisation API](api.md) for the ability to change "/charon" to a different value.

### Image Requests

@@ -26,6 +26,8 @@ Similarly, nextstrain.org is a server which has handlers for these three API end

See [the server API](server/api.md) for details about each of these requests.

> Note that "/charon" can be changed to any address you wich by customising the client at build time.
See [the client-cusomisation API](../customise-client/api) for more details.
## The "Default" Auspice Server

@@ -1,6 +1,6 @@
import queryString from "query-string";
import * as types from "./types";
import { charonAPIAddress } from "../util/globals";
import { getServerAddress } from "../util/globals";
import { goTo404 } from "./navigation";
import { createStateFromQueryOrJSONs, createTreeTooState } from "./recomputeReduxState";
import { loadFrequencies } from "./frequencies";
@@ -9,9 +9,6 @@ import { warningNotification, errorNotification } from "./notifications";
import { hasExtension, getExtension } from "../util/extensions";


/* TODO: make a default auspice server (not charon) and make charon the nextstrain server. Or vice versa. */
const serverAddress = hasExtension("serverAddress") ? getExtension("serverAddress") : charonAPIAddress;

/**
* Sends a GET request to the `/charon` web API endpoint requesting data.
* Throws an `Error` if the response is not successful or is not a redirect.
@@ -25,7 +22,7 @@ const serverAddress = hasExtension("serverAddress") ? getExtension("serverAddres
* query string such as `type` (`String`) or `narrative` (`Boolean`).
*/
const getDatasetFromCharon = (prefix, {type, narrative=false}={}) => {
let path = `${serverAddress}/${narrative?"getNarrative":"getDataset"}`;
let path = `${getServerAddress()}/${narrative?"getNarrative":"getDataset"}`;
path += `?prefix=${prefix}`;
if (type) path += `&type=${type}`;
const p = fetch(path)
@@ -216,7 +213,7 @@ const fetchDataAndDispatch = async (dispatch, url, query, narrativeBlocks) => {

/* Get available datasets -- this is needed for the sidebar dataset-change dropdowns etc */
try {
const availableDatasets = await fetchJSON(`${charonAPIAddress}/getAvailable?prefix=${window.location.pathname}`)
const availableDatasets = await fetchJSON(`${getServerAddress()}/getAvailable?prefix=${window.location.pathname}`)
dispatch({type: types.SET_AVAILABLE, data: availableDatasets});
} catch (err) {
console.error("Failed to fetch available datasets", err.message)
@@ -4,7 +4,7 @@ import DefaultSplashContent from "./splash";
import { hasExtension, getExtension } from "../../util/extensions";
import ErrorBoundary from "../../util/errorBoundry";
import { fetchJSON } from "../../util/serverInteraction";
import { charonAPIAddress, controlsHiddenWidth } from "../../util/globals";
import { getServerAddress, controlsHiddenWidth } from "../../util/globals";
import { changePage } from "../../actions/navigation";

const SplashContent = hasExtension("splashComponent") ?
@@ -25,7 +25,7 @@ class Splash extends React.Component {
this.state = {available: {}, errorMessage: undefined};
}
componentDidMount() {
fetchJSON(`${charonAPIAddress}/getAvailable?prefix=${this.props.reduxPathname}`)
fetchJSON(`${getServerAddress()}/getAvailable?prefix=${this.props.reduxPathname}`)
.then((json) => {
this.setState({available: json});
})
@@ -3,7 +3,7 @@ import { connect } from "react-redux";
import SingleDataset from "./single";
import { goTo404 } from "../../actions/navigation";
import { fetchJSON } from "../../util/serverInteraction";
import { charonAPIAddress } from "../../util/globals";
import { getServerAddress } from "../../util/globals";

@connect()
class Status extends React.Component {
@@ -12,7 +12,7 @@ class Status extends React.Component {
this.state = {available: undefined};
}
componentDidMount() {
fetchJSON(`${charonAPIAddress}/getAvailable?prefix=${window.location.pathname}`)
fetchJSON(`${getServerAddress()}/getAvailable?prefix=${window.location.pathname}`)
.then((json) => {this.setState({available: json});})
.catch((err) => {
console.warn(err);
@@ -1,5 +1,5 @@
import React from "react";
import { charonAPIAddress } from "../../util/globals";
import { getServerAddress } from "../../util/globals";
import { createStateFromQueryOrJSONs } from "../../actions/recomputeReduxState";
import { fetchJSON } from "../../util/serverInteraction";

@@ -20,7 +20,7 @@ class SingleDataset extends React.Component {
};
}
componentDidMount() {
fetchJSON(`${charonAPIAddress}/getDataset?prefix=${this.props.path}`)
fetchJSON(`${getServerAddress()}/getDataset?prefix=${this.props.path}`)
.then((json) => {
const state = createStateFromQueryOrJSONs({json, query: ""});
this.setState({
@@ -1,4 +1,5 @@
import { scaleLinear, scaleSqrt } from "d3-scale";
import { hasExtension, getExtension } from "../util/extensions";

export const colorOptions = {
"country": {"key": "country", "legendTitle": "Country", "menuItem": "country", "type": "discrete"},
@@ -134,8 +135,18 @@ export const filterAbbrRev = {"geographic location": "geo", "all": "all"};
export const titleColors = ["#4377CD", "#5097BA", "#63AC9A", "#7CB879", "#9ABE5C", "#B9BC4A", "#D4B13F", "#E49938", "#E67030", "#DE3C26"];
export const notificationDuration = 10000;

/* server init stuff */
export const charonAPIAddress = "/charon";
/**
* Get the prefix for server API requests
* This may be provided by extensions at build time
* Default value: "/charon"
*/
export const getServerAddress = () => {
if (hasExtension("serverAddress")) {
return getExtension("serverAddress")
.replace(/\/$/, ""); // remove trailing slash if present
}
return "/charon"; // default
};

export const months = {
1: 'Jan',

0 comments on commit 8e97d6f

Please sign in to comment.
You can’t perform that action at this time.