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).
This commit is contained in:
1 parent
8ee6cc07c9
commit
721e4bfe42
7 files changed
+27
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in new issue
Block a user