- Replace Express server with Next.js Route Handlers (16 API routes) - Rewrite index.html SPA as React components (feed, post, admin, modals) - Move style.css to app/globals.css with dark/light themes intact - Add lib/db.js, lib/auth.js (JWT), lib/api.js (client API wrapper) - Server binds 0.0.0.0 by default; host/port configurable via config.js - Uploads served via /api/uploads route (rewrite keeps /uploads/ URLs) - Multi-stage dockerfile using standalone output
// DELETE /api/links/[id]
|
|
import pool from '@/lib/db';
|
|
import { getUser, requireAdmin } from '@/lib/auth';
|
|
|
|
export async function DELETE(req, { params }) {
|
|
const user = getUser(req);
|
|
if (!user) {
|
|
return Response.json({ error: '请先登录' }, { status: 401 });
|
|
}
|
|
const forbidden = await requireAdmin(user);
|
|
if (forbidden) return forbidden;
|
|
try {
|
|
await pool.query('DELETE FROM friendly_links WHERE id = $1', [params.id]);
|
|
return Response.json({ success: true });
|
|
} catch {
|
|
return Response.json({ error: '删除失败,请稍后重试' }, { status: 500 });
|
|
}
|
|
}
|