Catched error when loading servers from a servers.json file

This commit is contained in:
Alejandro Celaya 2019-04-28 13:07:55 +02:00
parent 78c34a342d
commit 4c11d9c6d5
4 changed files with 13 additions and 9 deletions

1
.gitignore vendored
View file

@ -13,3 +13,4 @@ npm-debug.log*
docker-compose.override.yml
home
public/servers.json*

View file

@ -39,12 +39,13 @@ Official distributable files have been build so that they are served from the ro
If you need to host shlink-web-client yourself and serve it from a subpath, follow these steps:
* Download [node](https://nodejs.org/en/download/package-manager/) 10.15 or later (if you don't have it yet).
* Download shlink-web-client source files for the version you want to build.
* Download shlink-web-client source code for the version you want to build.
* For example, if you want to build `v1.0.1`, use this link https://github.com/shlinkio/shlink-web-client/archive/v1.0.1.zip
* Replace the `v1.0.1` part in the link with the one of the version you want to build.
* Decompress the file and `cd` into the resulting folder.
* Install project dependencies by running `npm install`.
* Open the `package.json` file in the root of the project, locate the `homepage` property and replace the value (which should be an empty string) by the path from which you want to serve shlink-web-client.
* For example: `"homepage": "/my-projects/shlink-web-client",`.
* Build the distributable contents by running `npm run build`.
* Once the command finishes, you will have a `build` folder with all the static assets you need to run shlink-web-client. Just place them wherever you want them to be served from.
* Build the project:
* For a static distributable file, run `npm run build`. Once the command finishes, you will have a `build` folder with all the static assets you need to run shlink-web-client. Just place them wherever you want them to be served from.
* For a docker image, run `docker build . -t shlink-web-client`. Once the command finishes, you will have an image with the name `shlink-web-client`.

View file

@ -1,5 +1,5 @@
import { handleActions } from 'redux-actions';
import { pipe, isEmpty, assoc, map } from 'ramda';
import { pipe, isEmpty, assoc, map, prop } from 'ramda';
import { v4 as uuid } from 'uuid';
import { homepage } from '../../../package.json';
@ -31,11 +31,13 @@ export const listServers = ({ listServers, createServers }, { get }) => () => as
}
// If local list is empty, try to fetch it remotely and calculate IDs for every server
const { data: remoteList } = await get(`${homepage}/servers.json`);
const listWithIds = map(assocId, remoteList);
const remoteList = await get(`${homepage}/servers.json`)
.then(prop('data'))
.then(map(assocId))
.catch(() => []);
createServers(listWithIds);
dispatch({ type: FETCH_SERVERS, list: listWithIds.reduce((map, server) => ({ ...map, [server.id]: server }), {}) });
createServers(remoteList);
dispatch({ type: FETCH_SERVERS, list: remoteList.reduce((map, server) => ({ ...map, [server.id]: server }), {}) });
};
export const createServer = ({ createServer }, listServersAction) => pipe(createServer, listServersAction);

View file

@ -52,4 +52,4 @@ export const useToggle = (initialValue = false) => {
return [ flag, () => setFlag(!flag) ];
};
export const wait = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds));
export const wait = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));