Reframe AI-tlas as a public research journal with authenticator-protected editorial workspace
Validate / validate (push) Successful in 3m15s

This commit is contained in:
2026-10-30 20:02:22 +08:00
parent b5de41501b
commit 712046e86f
18 changed files with 353 additions and 68 deletions
+4
View File
@@ -1,4 +1,5 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { COOKIE, validSession } from './editor-session';
export class HttpError extends Error {
constructor(public status: number, message: string) { super(message); }
@@ -10,6 +11,9 @@ type Handler = (req: NextApiRequest) => Promise<unknown>;
/** Dispatch by HTTP method; a handler returns the JSON to send, or throws HttpError. */
export function route(handlers: Partial<Record<Method, Handler>>) {
return async (req: NextApiRequest, res: NextApiResponse) => {
res.setHeader('Cache-Control', 'private, no-store');
if (!await validSession(req.cookies[COOKIE])) return res.status(401).json({ error: 'Editor authentication required' });
if (req.method !== 'GET' && req.headers.origin !== process.env.EDITOR_ORIGIN) return res.status(403).json({ error: 'Invalid origin' });
const h = handlers[req.method as Method];
if (!h) {
res.setHeader('Allow', Object.keys(handlers).join(', '));