Skip to content

Commit

Permalink
Add two new .env vars to allow dev instance to be anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjones-plip committed Jan 19, 2024
1 parent 889e361 commit a7f6865
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -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[];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
});
}

Expand Down
13 changes: 12 additions & 1 deletion src/lib/cht-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -224,4 +235,4 @@ function extractLineage(doc: any): string[] {
}

return [];
};
};

0 comments on commit a7f6865

Please sign in to comment.