diff --git a/env.example b/env.example index afc53619..ebc8c734 100644 --- a/env.example +++ b/env.example @@ -2,3 +2,5 @@ COOKIE_PRIVATE_KEY= CONFIG_NAME=chis-ke PORT=3000 # for development environment EXTERNAL_PORT=3000 # for docker +CHT_DEV_URL_PORT=localhost:5984 # where your dev CHT instance is, hostname:port +CHT_DEV_HTTP=false # 'false' for http 'true' for https diff --git a/src/config/index.ts b/src/config/index.ts index 14d3d623..c6dcba9b 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,6 +1,7 @@ import _ from "lodash"; import { ChtApi, PlacePayload } from "../lib/cht-api"; import getConfigByKey from "./config-factory"; +import {env} from "process"; export type ConfigSystem = { domains: AuthenticationInfo[]; @@ -55,6 +56,8 @@ export type AuthenticationInfo = { const { CONFIG_NAME, NODE_ENV, + CHT_DEV_URL_PORT, + CHT_DEV_HTTP } = process.env; const partnerConfig = getConfigByKey(CONFIG_NAME); @@ -139,11 +142,17 @@ export class Config { public static getDomains() : AuthenticationInfo[] { const domains = [...config.domains]; + // because all .env vars imported as strings, let's get the AuthenticationInfo object a boolean + let TMP_USE_HTTP = true; + if (CHT_DEV_HTTP === 'false') { + TMP_USE_HTTP = false + } + if (NODE_ENV !== 'production') { domains.push({ friendly: '$localhost', - domain: 'localhost:5988', - useHttp: true, + domain: CHT_DEV_URL_PORT as string, + useHttp: TMP_USE_HTTP, }); } diff --git a/src/lib/cht-api.ts b/src/lib/cht-api.ts index d42a048e..1d121ec7 100644 --- a/src/lib/cht-api.ts +++ b/src/lib/cht-api.ts @@ -3,6 +3,10 @@ import axios, { AxiosHeaders } from "axios"; import { UserPayload } from "../services/user-payload"; import { AuthenticationInfo, Config, ContactType } from "../config"; +const { + NODE_ENV +} = process.env; + export type ChtSession = { authInfo: AuthenticationInfo; sessionToken: string; @@ -64,6 +68,13 @@ export class ChtApi { const sessionToken = setCookieHeader?.[0].split(';') .find((header : string) => header.startsWith(COUCH_AUTH_COOKIE_NAME)); + if (NODE_ENV !== 'production') { + if (!sessionToken) { + console.log("failed to login to sever " + sessionUrl); + } else { + console.log("successfully logged in to sever " + sessionUrl); + } + } return { authInfo, username, @@ -224,4 +235,4 @@ function extractLineage(doc: any): string[] { } return []; -}; \ No newline at end of file +};