Skip to content

Commit

Permalink
fix: missing http:// in authCheck uri (#169)
Browse files Browse the repository at this point in the history
* reduce image size: ui-control, tester

* add /healthcheck to ui-control

* fix ui-control image

* clean up env variable in ui-control
  • Loading branch information
rtang03 authored Dec 19, 2020
1 parent cc42185 commit f0f32a9
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 36 deletions.
8 changes: 3 additions & 5 deletions deployments/dev-net/build.gw-org1/.env.local.ui
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
NODE_ENV=development
# GW_ORG_INTERNAL_HOST=http://gw-org1:4001
NODE_ENV=production
GW_ORG_EXTERNAL_HOST=http://localhost:4001/graphql
NEXT_PUBLIC_GW_ORG_EXTERNAL_HOST=http://localhost:4001/graphql
HOST=localhost
PORT=3000
QH_EXTERNAL_HOST=http://localhost:5001/graphql
NEXT_PUBLIC_GW_ORG_EXTERNAL_HOST=http://localhost:4001/graphql
NEXT_PUBLIC_QH_EXTERNAL_HOST=http://localhost:5001/graphql
PORT=3000
8 changes: 3 additions & 5 deletions deployments/dev-net/build.gw-org2/.env.local.ui
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
NODE_ENV=development
# GW_ORG_INTERNAL_HOST=http://gw-org2:4001
NODE_ENV=production
GW_ORG_EXTERNAL_HOST=http://localhost:4002/graphql
NEXT_PUBLIC_GW_ORG_EXTERNAL_HOST=http://localhost:4002/graphql
HOST=localhost
PORT=3000
QH_EXTERNAL_HOST=http://localhost:5002/graphql
NEXT_PUBLIC_GW_ORG_EXTERNAL_HOST=http://localhost:4002/graphql
NEXT_PUBLIC_QH_EXTERNAL_HOST=http://localhost:5002/graphql
PORT=3000
4 changes: 2 additions & 2 deletions deployments/dev-net/compose.1org.ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ services:
image: $UI_CONTROL_IMAGE-org1:$RELEASE
container_name: ui-control1
environment:
- HOST=localhost
# - HOST=localhost
- PORT=3000
- AUTH_HOST=http://auth-server1:8080
- GW_ORG_INTERNAL_HOST=http://gw-org1:4001
# - GW_ORG_INTERNAL_HOST=http://gw-org1:4001
- GW_ORG_EXTERNAL_HOST=http://localhost:4001
- QH_EXTERNAL_HOST=http://localhost:5001/graphql
networks:
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-control/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This is example for .env
NODE_ENV=development
GW_ORG_INTERNAL_HOST=http://gw-org1:4001
GW_ORG_EXTERNAL_HOST=http://localhost:8080
HOST=localhost
PORT=3000
AUTH_HOST=http://localhost:3001
QH_EXTERNAL_HOST=http://localhost:5001/graphql
10 changes: 7 additions & 3 deletions packages/ui-control/.env.local
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# IMPORTANT NOTE:
# .env.local is special file for use by NextJS
# Below env var will be available to NextJS browswer client
# .env is used by server/index.js for custom NextJS express server
# Therefore, BOTH .env and .env.local required.
AUTH_HOST=http://loalhost:3001
NODE_ENV=development
GW_ORG_INTERNAL_HOST=http://gw-org1:4001
GW_ORG_EXTERNAL_HOST=http://localhost:8080
HOST=localhost
PORT=3000
AUTH_HOST=http://localhost:3001
QH_EXTERNAL_HOST=http://localhost:5001/graphql
PORT=3000

# ORG2 CONFIG
#GW_ORG_INTERNAL_HOST=http://gw-org2:4001
Expand Down
33 changes: 17 additions & 16 deletions packages/ui-control/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,9 @@ import type { ApolloContext } from '../types';
import { getLogger } from '../utils';
import { schema } from './schema';

export const ENV = {
AUTH_HOST: process.env.AUTH_HOST as string,
NODE_ENV: process.env.NODE_ENV as string,
GW_ORG_INTERNAL_HOST: process.env.GW_ORG_INTERNAL_HOST as string,
GW_ORG_EXTERNAL_HOST: process.env.GW_ORG_EXTERNAL_HOST as string,
QH_EXTERNAL_HOST: process.env.QH_EXTERNAL_HOST as string,
PORT: (process.env.PORT as string) || '3000',
};
const logger = getLogger({ name: '[ui-control] index.js' });
const dev = ENV.NODE_ENV !== 'production';
const authUri = process.env.AUTH_HOST as string;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
const port = parseInt(process.env.PORT || '3000', 10);
Expand All @@ -36,13 +29,20 @@ const apolloServer = new ApolloServer({
const _accessToken = authorization?.split(' ')[1];
const accessToken = _accessToken === 'null' ? undefined : _accessToken;

return { res, accessToken, refreshToken, authUri: ENV.AUTH_HOST } as ApolloContext;
return { res, accessToken, refreshToken, authUri } as ApolloContext;
},
});

app
.prepare()
.then(() => {
if (!authUri) {
logger.error('environment variable $AUTH_HOST is empty');
process.exit(1);
}

logger.debug(util.format('Env - $AUTH_HOST: %s', authUri));

const server = express();
server.use(cookieParser());
server.use(express.json());
Expand All @@ -63,15 +63,16 @@ app
});

const onHealthCheck = async () => {
const auth = await fetch(`${ENV.AUTH_HOST}/oauth/authenticate/ping`)
const url = `${authUri}/oauth/authenticate/ping`;
const result = await fetch(url)
.then((res) => (res.status === httpStatus.OK ? { auth: 'ok' } : { auth: `${res.status}` }))
.catch((err) => ({ auth: util.format('unknown err: %j', err) }));
.catch((err) => ({ auth: util.format('url: %s, unknown err: %j', url, err) }));

logger.debug(util.format('onHealthCheck ${ENV.AUTH_HOST}/oauth/authenticate/ping: %j', auth));
logger.debug(util.format('onHealthCheck %s: %j', url, result));

return auth.auth === 'ok'
? Promise.resolve(auth)
: Promise.reject(new Error(util.format('checks: %j', auth)));
return result.auth === 'ok'
? Promise.resolve(result)
: Promise.reject(new Error(util.format('checks: %j', result)));
};

const onSignal = () =>
Expand Down
6 changes: 2 additions & 4 deletions packages/ui-control/utils/apolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ const bbfLink = new HttpLink({
// Also, process.env.QH_EXTERNAL_HOST will be available to browser, via .env.local

const queryHandlerLink = new HttpLink({
uri: process.env.NEXT_PUBLIC_QH_EXTERNAL_HOST || process.env.QH_EXTERNAL_HOST,
// uri: process.env.QH_EXTERNAL_HOST || 'http://localhost:5001/graphql',
uri: process.env.NEXT_PUBLIC_QH_EXTERNAL_HOST || process.env.QH_EXTERNAL_HOST || 'http://localhost:5001/graphql',
});

const gatewayLink = new HttpLink({
uri: process.env.NEXT_PUBLIC_GW_ORG_EXTERNAL_HOST || process.env.GW_ORG_EXTERNAL_HOST,
// uri: process.env.GW_ORG_EXTERNAL_HOST || 'http://localhost:4001/graphql',
uri: process.env.NEXT_PUBLIC_GW_ORG_EXTERNAL_HOST || process.env.GW_ORG_EXTERNAL_HOST || 'http://localhost:4001/graphql',
});

const condition = (dest: string) => ({ getContext }: Operation) => getContext().backend === dest;
Expand Down

0 comments on commit f0f32a9

Please sign in to comment.