-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphAPI.ts
35 lines (33 loc) · 1.06 KB
/
graphAPI.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { APIGatewayProxyResult } from "aws-lambda";
import { generateContentGraph } from "./graph";
export async function getGraph(): Promise<APIGatewayProxyResult> {
if (!process.env.CORS_ACCESS_CONTROL_ALLOW_ORIGINS) throw Error('No CORS setting found');
const headers: { [header: string]: string | number | boolean; } = {
'Access-Control-Allow-Origin': process.env.CORS_ACCESS_CONTROL_ALLOW_ORIGINS,
'Content-Type': 'application/json'
}
try {
return {
statusCode: 200,
body: JSON.stringify(await generateContentGraph()),
headers
}
}
catch (e) {
if (e instanceof Error) {
console.error(e.message);
return {
statusCode: 500,
body: JSON.stringify(e.message),
headers
}
} else {
console.error(e);
return {
statusCode: 400,
body: 'An unknown error occurred\n' + JSON.stringify(e),
headers
}
}
}
}