From 721e4bfe42bb3d81f6e24dfb12ba276e7071d725 Mon Sep 17 00:00:00 2001 From: lezi-fun <177434121+lezi-fun@users.noreply.github.com> Date: Mon, 10 Aug 2026 11:02:11 +0800 Subject: [PATCH] fix: 405 on write methods in Vercel (static GET optimization) Route handlers with both GET and write methods get the GET statically optimized on Vercel, which 405s POST/PUT/DELETE. Add export const dynamic = 'force-dynamic' to all 7 affected routes (settings, posts, custom-pages, event-logs, links, conversations, reports). --- app/api/admin/custom-pages/route.js | 4 ++++ app/api/conversations/route.js | 4 ++++ app/api/event-logs/route.js | 4 ++++ app/api/links/route.js | 4 ++++ app/api/posts/route.js | 4 ++++ app/api/reports/route.js | 4 ++++ app/api/settings/route.js | 3 +++ 7 files changed, 27 insertions(+) diff --git a/app/api/admin/custom-pages/route.js b/app/api/admin/custom-pages/route.js index e264419..c968300 100644 --- a/app/api/admin/custom-pages/route.js +++ b/app/api/admin/custom-pages/route.js @@ -2,6 +2,10 @@ import pool from '@/lib/db'; import { getUser, requireAdmin } from '@/lib/auth'; +// 避免 GET 被静态优化导致写方法 405(动态接口,不能缓存) +export const dynamic = 'force-dynamic'; + + export async function GET(req) { const user = getUser(req); const forbidden = await requireAdmin(user); diff --git a/app/api/conversations/route.js b/app/api/conversations/route.js index e738893..96def92 100644 --- a/app/api/conversations/route.js +++ b/app/api/conversations/route.js @@ -2,6 +2,10 @@ import pool from '@/lib/db'; import { getUser } from '@/lib/auth'; +// 避免 GET 被静态优化导致写方法 405(动态接口,不能缓存) +export const dynamic = 'force-dynamic'; + + export async function GET(req) { const user = getUser(req); if (!user) { diff --git a/app/api/event-logs/route.js b/app/api/event-logs/route.js index b9176a2..d493b3d 100644 --- a/app/api/event-logs/route.js +++ b/app/api/event-logs/route.js @@ -2,6 +2,10 @@ import pool from '@/lib/db'; import { getUser, requireAdmin } from '@/lib/auth'; +// 避免 GET 被静态优化导致写方法 405(动态接口,不能缓存) +export const dynamic = 'force-dynamic'; + + export async function GET(req) { const user = getUser(req); if (!user) { diff --git a/app/api/links/route.js b/app/api/links/route.js index 70d12de..c6c77dc 100644 --- a/app/api/links/route.js +++ b/app/api/links/route.js @@ -2,6 +2,10 @@ import pool from '@/lib/db'; import { getUser, requireAdmin } from '@/lib/auth'; +// 避免 GET 被静态优化导致写方法 405(动态接口,不能缓存) +export const dynamic = 'force-dynamic'; + + export async function GET() { try { const r = await pool.query('SELECT * FROM friendly_links ORDER BY sort_order'); diff --git a/app/api/posts/route.js b/app/api/posts/route.js index f017e8e..06b4b6d 100644 --- a/app/api/posts/route.js +++ b/app/api/posts/route.js @@ -2,6 +2,10 @@ import pool from '@/lib/db'; import { getUser } from '@/lib/auth'; +// 避免 GET 被静态优化导致写方法 405(动态接口,不能缓存) +export const dynamic = 'force-dynamic'; + + export async function GET(req) { const url = new URL(req.url); const sort = url.searchParams.get('sort') === 'hot' ? 'updated_at' : 'created_at'; diff --git a/app/api/reports/route.js b/app/api/reports/route.js index 3828598..b938e65 100644 --- a/app/api/reports/route.js +++ b/app/api/reports/route.js @@ -2,6 +2,10 @@ import pool from '@/lib/db'; import { getUser, requireAdmin } from '@/lib/auth'; +// 避免 GET 被静态优化导致写方法 405(动态接口,不能缓存) +export const dynamic = 'force-dynamic'; + + export async function GET(req) { const user = getUser(req); const forbidden = await requireAdmin(user); diff --git a/app/api/settings/route.js b/app/api/settings/route.js index e736c09..2bb57ae 100644 --- a/app/api/settings/route.js +++ b/app/api/settings/route.js @@ -2,6 +2,9 @@ import pool from '@/lib/db'; import { getUser, requireAdmin } from '@/lib/auth'; +// 避免 GET 被静态优化导致 PUT 405(动态接口,不能缓存) +export const dynamic = 'force-dynamic'; + export async function GET() { try { const r = await pool.query('SELECT key, value FROM settings');