Skip to content

Commit

Permalink
Add Vercel Cron (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
typeofweb authored Jan 5, 2024
1 parent bea3a92 commit 64f4676
Show file tree
Hide file tree
Showing 7 changed files with 3,388 additions and 7,529 deletions.
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

1 comment on commit 64f4676

@vercel
Copy link

@vercel vercel bot commented on 64f4676 Jan 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

polskifrontend – ./

polskifrontend-git-main-typeofweb.vercel.app
polskifrontend-typeofweb.vercel.app
polskifrontend.pl

Please sign in to comment.