-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcore.ts
More file actions
35 lines (28 loc) · 1005 Bytes
/
core.ts
File metadata and controls
35 lines (28 loc) · 1005 Bytes
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 { Context, Middleware } from 'koa';
import { githubOAuth2 } from 'next-ssr-middleware';
import { githubClient } from '../../../models/Base';
import { ProxyBaseURL, VERCEL } from '../../../models/configuration';
export const proxyGithub = async <T>({
method,
url,
headers: { host, ...headers },
request,
}: Context) => {
const path = url!.slice(`/api/GitHub/`.length),
body = Reflect.get(request, 'body');
// @ts-expect-error KoAJAX type compatibility
return githubClient.request<T>({ method, path, headers, body });
};
export const proxyGitHubAll: Middleware = async context => {
const { status, body } = await proxyGithub(context);
context.status = status;
context.body = body;
};
const client_id = process.env.GITHUB_OAUTH_CLIENT_ID!,
client_secret = process.env.GITHUB_OAUTH_CLIENT_SECRET!;
export const githubOAuth = githubOAuth2({
rootBaseURL: VERCEL ? undefined : `${ProxyBaseURL}/github.com/`,
client_id,
client_secret,
scopes: ['user', 'repo'],
});