File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments