diff --git a/app/api/companies/process/route.ts b/app/api/companies/process/route.ts index f896e12..4e9c112 100644 --- a/app/api/companies/process/route.ts +++ b/app/api/companies/process/route.ts @@ -4,7 +4,8 @@ import { createPlatform } from '@/lib/hiring-platforms/registry' import { logger } from '@/lib/logger' import type { NonNullableProperty } from '@/lib/types/utils' -import { StatusCodes } from 'http-status-codes' +import { ReasonPhrases, StatusCodes } from 'http-status-codes' +import { headers } from 'next/headers' // TODO: Express this through type also, on a lower level const isHiringPlatform = ( @@ -12,7 +13,21 @@ const isHiringPlatform = ( ): company is NonNullableProperty => company.trackerType === 'hiring_platform' -export const POST = async () => { +export const GET = async () => { + const headerList = headers() + const auth = headerList.get('Authorization') + + if (auth !== `Bearer ${process.env.CRON_SECRET}`) { + return Response.json( + { + message: ReasonPhrases.UNAUTHORIZED, + }, + { + status: StatusCodes.UNAUTHORIZED, + }, + ) + } + logger.info('Processing companies and fetching jobs') try { diff --git a/middleware.ts b/middleware.ts index b9a6451..11fc89f 100644 --- a/middleware.ts +++ b/middleware.ts @@ -1,6 +1,6 @@ import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server' -const isPublic = createRouteMatcher([]) +const isPublic = createRouteMatcher(['/api/companies/process']) export default clerkMiddleware((auth, request) => { if (!isPublic(request)) { diff --git a/package.json b/package.json index 83afef1..c57fb53 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "PORT=4000 next dev | pino-pretty", "build": "next build", + "build:vercel": "bun db:migrate && next build", "start": "next start", "lint": "next lint", "typecheck": "tsc --noEmit", diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..666afe9 --- /dev/null +++ b/vercel.json @@ -0,0 +1,8 @@ +{ + "crons": [ + { + "path": "/api/companies/process", + "schedule": "0 10 * * *" + } + ] +}