Skip to content

Commit bb63723

Browse files
Point each stage at its own API hosts so people-search lookups reach the other APIs (#15)
1 parent 46c9173 commit bb63723

6 files changed

Lines changed: 61 additions & 20 deletions

File tree

‎config/demo.json‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"appEnv": "demo",
3+
"appName": "AskApi",
4+
"contentRoot": "https://ask.demo.churchapps.org",
5+
"fileStore": "S3",
6+
"mailSystem": "SES",
7+
"membershipApi": "https://api.demo.churchapps.org/membership",
8+
"attendanceApi": "https://api.demo.churchapps.org/attendance",
9+
"contentApi": "https://api.demo.churchapps.org/content",
10+
"doingApi": "https://api.demo.churchapps.org/doing",
11+
"givingApi": "https://api.demo.churchapps.org/giving",
12+
"messagingApi": "https://api.demo.churchapps.org/messaging",
13+
"reportingApi": "https://api.demo.churchapps.org/reporting",
14+
"s3Bucket": "demo-churchapps-ask",
15+
"aiProvider": "openrouter"
16+
}

‎config/prod.json‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"contentRoot": "https://ask.churchapps.org",
55
"fileStore": "S3",
66
"mailSystem": "SES",
7-
"membershipApi": "https://membershipapi.churchapps.org",
8-
"attendanceApi": "https://attendanceapi.churchapps.org",
9-
"contentApi": "https://contentapi.churchapps.org",
10-
"doingApi": "https://doingapi.churchapps.org",
11-
"givingApi": "https://givingapi.churchapps.org",
7+
"membershipApi": "https://api.churchapps.org/membership",
8+
"attendanceApi": "https://api.churchapps.org/attendance",
9+
"contentApi": "https://api.churchapps.org/content",
10+
"doingApi": "https://api.churchapps.org/doing",
11+
"givingApi": "https://api.churchapps.org/giving",
1212
"s3Bucket": "churchapps-ask",
13-
"messagingApi": "https://messagingapi.churchapps.org",
14-
"reportingApi": "https://reportingapi.churchapps.org",
13+
"messagingApi": "https://api.churchapps.org/messaging",
14+
"reportingApi": "https://api.churchapps.org/reporting",
1515
"aiProvider": "openrouter"
16-
}
16+
}

‎config/staging.json‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"contentRoot": "https://ask.staging.churchapps.org",
55
"fileStore": "S3",
66
"mailSystem": "SES",
7-
"membershipApi": "https://membershipapi.staging.churchapps.org",
8-
"attendanceApi": "https://attendanceapi.staging.churchapps.org",
9-
"contentApi": "https://contentapi.staging.churchapps.org",
10-
"doingApi": "https://doingapi.staging.churchapps.org",
11-
"givingApi": "https://givingapi.staging.churchapps.org",
7+
"membershipApi": "https://api.staging.churchapps.org/membership",
8+
"attendanceApi": "https://api.staging.churchapps.org/attendance",
9+
"contentApi": "https://api.staging.churchapps.org/content",
10+
"doingApi": "https://api.staging.churchapps.org/doing",
11+
"givingApi": "https://api.staging.churchapps.org/giving",
1212
"s3Bucket": "staging-churchapps-ask",
13-
"messagingApi": "https://messagingapi.staging.churchapps.org",
14-
"reportingApi": "https://reportingapi.staging.churchapps.org",
13+
"messagingApi": "https://api.staging.churchapps.org/messaging",
14+
"reportingApi": "https://api.staging.churchapps.org/reporting",
1515
"aiProvider": "openrouter"
16-
}
16+
}

‎src/helpers/Environment.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ export class Environment extends EnvironmentBase {
1515

1616
static async init(environment: string) {
1717
if (!environment) throw new Error("APP_ENV is required");
18-
// No demo.json in this project; demo runs on the dev config.
19-
const data = await this.initBase(environment, { appName: "askApi", fileMap: { demo: "dev.json" } });
18+
const data = await this.initBase(environment, { appName: "askApi" });
2019

2120
this.membershipApi = this.requireHost(data.membershipApi, "membershipApi");
2221
this.attendanceApi = this.requireHost(data.attendanceApi, "attendanceApi");

‎src/helpers/__tests__/DataHelper.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("executeApiCalls hosts", () => {
5757
assert.ok(seen.length > 0);
5858
for (const url of seen) {
5959
assert.equal(url.includes(".staging.churchapps.org"), false);
60-
assert.match(url, /^https:\/\/[a-z]+api\.churchapps\.org$/);
60+
assert.match(url, /^https:\/\/api\.churchapps\.org\/[a-z]+$/);
6161
}
6262
});
6363

@@ -79,7 +79,7 @@ describe("Environment hosts", () => {
7979
const hosts = Environment.apiHosts();
8080
for (const url of Object.values(hosts)) {
8181
assert.equal(url.includes(".staging.churchapps.org"), false);
82-
assert.match(url, /^https:\/\/[a-z]+api\.churchapps\.org$/);
82+
assert.match(url, /^https:\/\/api\.churchapps\.org\/[a-z]+$/);
8383
}
8484
});
8585
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import assert from "node:assert/strict";
2+
import fs from "node:fs";
3+
import path from "node:path";
4+
import { describe, it } from "node:test";
5+
6+
// The Lambda talks to the other ChurchApps APIs with the hosts in config/<stage>.json. Demo used to fall
7+
// back to dev.json, whose hosts are localhost, so every people-search lookup (groups, attendance,
8+
// donations) failed in demo and matched nobody. The legacy per-module hostnames redirect across hosts,
9+
// which drops the Authorization header, so prod has to name the api.churchapps.org/<module> form too.
10+
const modules = ["membership", "attendance", "content", "doing", "giving", "messaging", "reporting"];
11+
const stages: { [file: string]: string } = {
12+
"demo.json": "https://api.demo.churchapps.org",
13+
"staging.json": "https://api.staging.churchapps.org",
14+
"prod.json": "https://api.churchapps.org"
15+
};
16+
17+
describe("stage configs", () => {
18+
for (const [file, base] of Object.entries(stages)) {
19+
it(`${file} points every module host at ${base}/<module>`, () => {
20+
const config = JSON.parse(fs.readFileSync(path.resolve("config", file), "utf8"));
21+
for (const m of modules) {
22+
assert.equal(config[`${m}Api`], `${base}/${m}`, `${file} ${m}Api`);
23+
}
24+
});
25+
}
26+
});

0 commit comments

Comments
 (0)