Skip to content

Commit db3708e

Browse files
Various enhancements
* Better HTTP handling, nocache, logging
1 parent 1ef28ba commit db3708e

5 files changed

Lines changed: 18 additions & 19 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"js-yaml": "^4.1.0",
3838
"ldap-escape": "^2.0.6",
3939
"ldapjs": "^3.0.1",
40+
"nocache": "^4.0.0",
4041
"octokit": "^2.0.14",
4142
"openapi-backend": "^5.9.1",
4243
"swagger-ui-express": "^4.6.2"

src/app.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import fs from "fs";
55
import path from "node:path";
66
import swaggerUi from "swagger-ui-express";
77
import { routes } from "./routes";
8-
import { Log, SetupLogging } from "./logging";
8+
import { SetupLogging } from "./logging";
9+
import nocache from "nocache";
910

1011
SetupLogging();
1112

1213
const app = express();
14+
app.use(nocache());
1315

1416
const port = process.env.PORT;
1517

src/handlers/getSourceTeam.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ export async function getSourceTeamHandler(
77
c: Context,
88
_req: Request,
99
res: Response
10-
) {
10+
) {
1111
const teamName = _req.query.teamName as string;
1212

1313
Log(`Searching SoT for ${teamName}`)
1414

1515
const result = await SearchAllAsync(teamName)
1616

17-
Log(`Found in SoT: ${JSON.stringify(result)}`)
17+
if (result.Succeeded) {
18+
Log(`Found in SoT: ${JSON.stringify(result)}`)
19+
return res.status(200).json(result);
20+
}
1821

19-
return res.status(200).json(result);
22+
return res.status(500).json(result)
2023
}

src/openapi.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ paths:
100100
schema:
101101
type: string
102102
required: true
103-
- in: query
104-
name: cb
105-
description: For use in cache busting
106-
schema:
107-
type: string
108-
required: false
109103
responses:
110104
"200":
111105
description: A successful response

src/services/ldapClient.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,19 @@ export async function SearchAllAsync(groupName: string): SearchAllResponse {
140140
}
141141
}
142142

143+
// TODO: do not directly use axios.create from within a function like this
144+
// it will cause a new client to be made per request.
145+
const httpClient = axios.create();
146+
axiosRetry(httpClient, { retries: 5 });
147+
143148
async function ForwardSearch(groupName: string) : SearchAllResponse {
144149
Log(`Forwarding request to '${process.env.SOURCE_PROXY}'`);
145-
146-
// cb is for cache busting.
147-
const requestUrl = `${process.env.SOURCE_PROXY}/api/get-source-team?teamName=${groupName}&cb=${Date.now()}`;
150+
151+
const requestUrl = `${process.env.SOURCE_PROXY}/api/get-source-team?teamName=${groupName}}`;
148152

149153
Log(`Retrieving group (${groupName}) information from '${requestUrl}'`);
150154
try{
151-
// TODO: do not directly use axios.create from within a function like this
152-
// it will cause a new client to be made per request.
153-
const client = axios.create();
154-
axiosRetry(client, { retries: 5 });
155-
156-
const result = await client.get(requestUrl);
155+
const result = await httpClient.get(requestUrl);
157156
Log(`Results for ${groupName}: ${result}`);
158157
return result.data as SearchAllResponse;
159158
}

0 commit comments

Comments
 (0)