Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vercel Cron #202

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
20
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"eslint.packageManager": "pnpm",
"eslint.run": "onSave",
"editor.codeActionsOnSave": {
"source.fixAll": true
"source.fixAll": "explicit"
},
"typescript.enablePromptUseWorkspaceTsdk": true
}
3 changes: 3 additions & 0 deletions api-helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type NameToType = {
readonly YOUTUBE_API_KEY: string;
readonly CAPTCHA_SECRET_KEY: string;
readonly ALGOLIA_API_SECRET: string;
readonly CRON_SECRET: string;

readonly NEXT_PUBLIC_URL: string;
readonly NEXT_PUBLIC_SUPABASE_URL: string;
Expand All @@ -35,6 +36,8 @@ function getConfigForName(name: keyof NameToType): Nil<NameToType[keyof NameToTy
return process.env.DATABASE_URL;
case 'FEED_UPDATE_SECRET':
return process.env.FEED_UPDATE_SECRET;
case 'CRON_SECRET':
return process.env.CRON_SECRET;
case 'YOUTUBE_API_KEY':
return process.env.YOUTUBE_API_KEY;
case 'CAPTCHA_SECRET_KEY':
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@
"wait-on": "7.0.1"
},
"engines": {
"npm": ">=7.0.0",
"pnpm": ">=7.11.0",
"node": ">=18.0.0 <19"
"npm": ">=10.0.0",
"pnpm": ">=8.10.0",
"node": ">=20.0.0 <21"
},
"packageManager": "pnpm@7.17.0",
"packageManager": "pnpm@8.10.0",
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --resolve-plugins-relative-to . --fix",
Expand Down
13 changes: 13 additions & 0 deletions pages/api/update-feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ import { updateFeeds } from '../../api-helpers/feedFunctions';

export default withAsync(
withMethods({
// VERCEL CRON
GET: withDb(async (req) => {
const isSecretValid = Crypto.timingSafeEqual(
Buffer.from(req.headers.authorization ?? ''),
Buffer.from(`Bearer ${getConfig('CRON_SECRET')}`),
);
if (!isSecretValid) {
throw Boom.unauthorized();
}
await updateFeeds(req.db);
return null;
}),
// LOCAL
PATCH: withValidation({
body: object({ secret: string().required() }).required(),
})(
Expand Down
Loading
Loading