From 4c11d9c6d5d5c2dcad5e402d6dcf02c2683af9cd Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 28 Apr 2019 13:07:55 +0200 Subject: [PATCH] Catched error when loading servers from a servers.json file --- .gitignore | 1 + README.md | 7 ++++--- src/servers/reducers/server.js | 12 +++++++----- src/utils/utils.js | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 19285d6a..1b558dfb 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ npm-debug.log* docker-compose.override.yml home +public/servers.json* diff --git a/README.md b/README.md index 79c8f16a..2c2442ad 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/src/servers/reducers/server.js b/src/servers/reducers/server.js index 17ac2662..f1624027 100644 --- a/src/servers/reducers/server.js +++ b/src/servers/reducers/server.js @@ -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); diff --git a/src/utils/utils.js b/src/utils/utils.js index 5f416bca..b1daf53b 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -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));