この
この
この
- タグクラウド
- 検索モーダルを
開いた ときの 初期表示 - 記事下部に
ある 関連記事
今は
法
実装方- Vercel の
Deploy Hook を 作成する - Vercel の
Cron Jobs を 使う - デプロイを
実行する API を 作成する
やる
Deploy Hook を 作成する
Vercel のまずは
この
ただし、
デフォルトだと?buildCache=false
を
Cron Jobs を 設定する
Vercel の次に、
vercel.json
に
{ "crons": [ { "path": "/api/cron/deploy", "schedule": "0 18 * * *" } ]}
ここで0 18 * * *
と
ちなみに
実行する API を 作成する
デプロイをあとは/api/cron/deploy
に
import { env } from "#/env";
const createResponse = (message: string, status: number) => new Response(message, { status, headers: { "Content-Type": "text/plain", "X-Content-Type-Options": "nosniff", }, });
export const GET = async (request: Request) => { const webhookUrl = env.VERCEL_DEPLOY_HOOK_URL;
if (!webhookUrl) { return createResponse("Deploy hook URL is missing", 500); }
const authHeader = request.headers.get("authorization");
if (authHeader !== `Bearer ${env.CRON_SECRET}`) { return createResponse("Unauthorized", 401); }
try { const response = await fetch(webhookUrl, { method: "POST" });
if (response.ok) { return createResponse("Redeployment triggered", 200); }
console.error( `Failed to trigger redeployment: ${response.status} ${response.statusText}`, );
return createResponse("Failed to trigger redeployment", 500); } catch (error) { console.error("Error communicating with deploy hook", error); return createResponse("Error communicating with deploy hook", 500); }};
ここで
それはCRON_SECRET
)をAuthorization
Bearer
トークン のCRON_SECRET
と
このCRON_SECRET
を
動くかテスト
実際に実装に
curl -X GET "https://xxx.com/api/cron/deploy" \-H "Authorization: Bearer xxx"
ごに
さい何でも