Skip to content

Commit 31c84cc

Browse files
committed
debug(api): add diagnose-network endpoint
1 parent 1b10f4f commit 31c84cc

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

apps/api/src/feed/feed.controller.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,35 @@ export class FeedController {
2121
const user = req.user as User;
2222
return this.feedService.getDebugFeed(user.id);
2323
}
24+
25+
@Get('diagnose-network')
26+
async diagnoseNetwork() {
27+
const results: any = {};
28+
const dns = require('dns/promises');
29+
30+
try {
31+
results.dns = await dns.lookup('api.openai.com', { all: true });
32+
} catch (e: any) {
33+
results.dns = { error: e.message };
34+
}
35+
36+
try {
37+
const start = Date.now();
38+
const res = await fetch('https://api.openai.com/v1/models', {
39+
headers: {
40+
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
41+
}
42+
});
43+
results.fetch = {
44+
status: res.status,
45+
statusText: res.statusText,
46+
duration: Date.now() - start,
47+
body: (await res.text()).substring(0, 1000),
48+
};
49+
} catch (e: any) {
50+
results.fetch = { error: e.message, stack: e.stack };
51+
}
52+
53+
return results;
54+
}
2455
}

0 commit comments

Comments
 (0)