From 32de1f0ac250f3c3f3a0809b3d44a18c7d0bf2d6 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Thu, 11 Jun 2020 15:08:20 -0500 Subject: [PATCH] Fix some errors running behind a proxy. --- packages/console-app/src/client.js | 11 +++++++---- packages/console-app/src/components/AppLink.js | 8 +++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/console-app/src/client.js b/packages/console-app/src/client.js index 1a79462..e67a25d 100644 --- a/packages/console-app/src/client.js +++ b/packages/console-app/src/client.js @@ -8,12 +8,15 @@ import { InMemoryCache } from 'apollo-cache-inmemory'; import { createResolvers } from './resolvers'; -const defaultServer = `${window.location.origin}/${window.location.pathname}` +const defaultServer = `${window.location.origin}`; export const graphqlApi = config => { - const { api: { server = defaultServer, path = '/api/graphql' } } = config; - - return `${server}${path}`; + const { api: { server = defaultServer, port = '', path = '/api' } } = config; + let base = server; + if (port) { + base = `${base}:${port}`; + } + return `${base}${path}`; }; /** diff --git a/packages/console-app/src/components/AppLink.js b/packages/console-app/src/components/AppLink.js index 3fd2705..85999a6 100644 --- a/packages/console-app/src/components/AppLink.js +++ b/packages/console-app/src/components/AppLink.js @@ -3,6 +3,7 @@ // import React from 'react'; +import get from 'lodash.get'; import Link from '@material-ui/core/Link'; import { getServiceUrl } from '../util/config'; @@ -12,11 +13,12 @@ const getAppUrl = (config, { name, version }) => { const pathComponents = [base]; // TODO(burdon): Fix. - // `wire app serve` expects the /wrn/ prefix. + // `wire app serve` expects the /app/ prefix. // That is OK in the production config where we can make it part of the the route, // but in development it must be prepended since we don't want to make it part of services.app.server. - if (!base.startsWith(`/${config.services.app.prefix}`) && !base.endsWith(`/${config.services.app.prefix}`)) { - pathComponents.push(config.services.app.prefix.substring(1)); + const prefix = get(config, 'services.app.prefix'); + if (prefix && !base.startsWith(`/${prefix}`) && !base.endsWith(`/${prefix}`)) { + pathComponents.push(prefix.substring(1)); } if (version) {