Files
twenty_crm/packages/twenty-website/src/app/api/github-stars/route.tsx
Ady Beraud b438fc2754 Fix github stars endpoint (#5301)
- Encapsulated GitHub star response in an object
- Fixed rounding of Github stars to align with Github convention
- Fixed CORS issue so that endpoint can be called from twenty.com and
app.twenty.com

Co-authored-by: Ady Beraud <a.beraud96@gmail.com>
2024-05-07 08:35:54 +02:00

27 lines
675 B
TypeScript

import { desc } from 'drizzle-orm';
import { findOne } from '@/database/database';
import { githubStarsModel } from '@/database/model';
import { formatNumberOfStars } from '@/shared-utils/formatNumberOfStars';
export const dynamic = 'force-dynamic';
export async function GET() {
try {
const githubStars = await findOne(
githubStarsModel,
desc(githubStarsModel.timestamp),
);
const githubNumberOfStars = formatNumberOfStars(
githubStars[0].numberOfStars,
);
return Response.json({ githubNumberOfStars });
} catch (error: any) {
return new Response(`Github stars error: ${error?.message}`, {
status: 500,
});
}
}