1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
const path = url.searchParams.get("path");
const apiUrl = new URL(path, "https://api.company-information.service.gov.uk/");
const apiKey = Deno.env.get("companiesHouseApiKey");
const basicAuth = btoa(apiKey + ":");
const response = await fetch(apiUrl, {
headers: { Authorization: `Basic ${basicAuth}` },
});
if (!response.ok) {
return new Response(await response.text(), {
status: response.status,
statusText: response.statusText,
});
}
const data = await response.json();
return Response.json(data);
}