fix: cors

This commit is contained in:
Ephraim Atta-Duncan
2024-10-23 22:03:10 +00:00
parent 62c4c32be5
commit d80634e0d0
8 changed files with 264 additions and 119 deletions

View File

@@ -1,12 +1,25 @@
import { NextResponse } from 'next/server';
import cors from '@/lib/cors';
import { requestHandler } from '@/app/request-handler';
export const GET = requestHandler(async () => {
export async function GET(request: Request) {
const res = await fetch('https://api.github.com/repos/documenso/documenso');
const { forks_count } = await res.json();
return NextResponse.json({
data: forks_count,
});
});
return cors(
request,
new Response(JSON.stringify({ data: forks_count }), {
status: 200,
headers: {
'content-type': 'application/json',
},
}),
);
}
export function OPTIONS(request: Request) {
return cors(
request,
new Response(null, {
status: 204,
}),
);
}

View File

@@ -1,14 +1,27 @@
import { NextResponse } from 'next/server';
import cors from '@/lib/cors';
import { requestHandler } from '@/app/request-handler';
export const GET = requestHandler(async () => {
export async function GET(request: Request) {
const res = await fetch(
'https://api.github.com/search/issues?q=repo:documenso/documenso+type:issue+state:open&page=0&per_page=1',
);
const { total_count } = await res.json();
return NextResponse.json({
data: total_count,
});
});
return cors(
request,
new Response(JSON.stringify({ data: total_count }), {
status: 200,
headers: {
'content-type': 'application/json',
},
}),
);
}
export function OPTIONS(request: Request) {
return cors(
request,
new Response(null, {
status: 204,
}),
);
}

View File

@@ -1,14 +1,27 @@
import { NextResponse } from 'next/server';
import cors from '@/lib/cors';
import { requestHandler } from '@/app/request-handler';
export const GET = requestHandler(async () => {
export async function GET(request: Request) {
const res = await fetch(
'https://api.github.com/search/issues?q=repo:documenso/documenso/+is:pr+merged:>=2010-01-01&page=0&per_page=1',
);
const { total_count } = await res.json();
return NextResponse.json({
data: total_count,
});
});
return cors(
request,
new Response(JSON.stringify({ data: total_count }), {
status: 200,
headers: {
'content-type': 'application/json',
},
}),
);
}
export function OPTIONS(request: Request) {
return cors(
request,
new Response(null, {
status: 204,
}),
);
}

View File

@@ -1,4 +1,6 @@
import { type NextRequest, NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import cors from '@/lib/cors';
const paths = [
{ path: '/forks', description: 'GitHub Forks' },
@@ -13,5 +15,22 @@ export function GET(request: NextRequest) {
return { path: url + path, description };
});
return NextResponse.json(apis);
return cors(
request,
new Response(JSON.stringify(apis), {
status: 200,
headers: {
'content-type': 'application/json',
},
}),
);
}
export function OPTIONS(request: Request) {
return cors(
request,
new Response(null, {
status: 204,
}),
);
}

View File

@@ -1,12 +1,25 @@
import { NextResponse } from 'next/server';
import cors from '@/lib/cors';
import { requestHandler } from '@/app/request-handler';
export const GET = requestHandler(async () => {
export async function GET(request: Request) {
const res = await fetch('https://api.github.com/repos/documenso/documenso');
const { stargazers_count } = await res.json();
return NextResponse.json({
data: stargazers_count,
});
});
return cors(
request,
new Response(JSON.stringify({ data: stargazers_count }), {
status: 200,
headers: {
'content-type': 'application/json',
},
}),
);
}
export function OPTIONS(request: Request) {
return cors(
request,
new Response(null, {
status: 204,
}),
);
}