MCPcopy Create free account
hub / github.com/compiler-explorer/compiler-explorer / handler

Method handler

lib/storage/remote.ts:56–85  ·  view source on GitHub ↗
(req: express.Request, res: express.Response)

Source from the content-addressed store, hash-verified

54 }
55
56 override async handler(req: express.Request, res: express.Response) {
57 let resp: Response;
58 let responseBody: any;
59 try {
60 resp = await this.post('/api/shortener', {
61 headers: {
62 'Content-Type': 'application/json',
63 },
64 body: JSON.stringify(req.body),
65 });
66 responseBody = await resp.json();
67 } catch (err: any) {
68 logger.error(err);
69 res.status(500);
70 res.end(err.message);
71 return;
72 }
73
74 const url = responseBody.url;
75 if (!url) {
76 res.status(resp.status);
77 res.send(resp.body);
78 return;
79 }
80
81 const relativeUrl = url.substring(url.lastIndexOf('/z/') + 1);
82 const shortlink = `${req.protocol}://${req.get('host')}${this.httpRootDir}${relativeUrl}`;
83
84 res.send({url: shortlink});
85 }
86
87 async expandId(id: string): Promise<ExpandedShortLink> {
88 const resp = await this.get(`/api/shortlinkinfo/${id}`);

Callers 1

handleMethod · 0.80

Calls 5

jsonMethod · 0.80
errorMethod · 0.80
statusMethod · 0.80
getMethod · 0.65
sendMethod · 0.45

Tested by

no test coverage detected