hatch-surf/node_modules/next/dist/esm/next-devtools/server/devtools-config-middleware.js
Riley Zhang df378d33ef
Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Merge GitHub main into Gitea repo (allow unrelated histories)
Resolved conflicts by taking GitHub versions for:
- .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml

Kept deploy.sh updated to:
- Pull from GitHub (primary source)
- Push to Gitea (push-mirror)
- Build from site/ directory (GitHub structure)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-25 05:20:46 +02:00

54 lines
2.3 KiB
JavaScript

import { existsSync } from 'fs';
import { readFile, writeFile, mkdir } from 'fs/promises';
import { dirname, join } from 'path';
import { middlewareResponse } from './middleware-response';
import { devToolsConfigSchema } from '../shared/devtools-config-schema';
import { deepMerge } from '../shared/deepmerge';
const DEVTOOLS_CONFIG_FILENAME = 'next-devtools-config.json';
const DEVTOOLS_CONFIG_MIDDLEWARE_ENDPOINT = '/__nextjs_devtools_config';
export function devToolsConfigMiddleware({ distDir, sendUpdateSignal }) {
const configPath = join(distDir, 'cache', DEVTOOLS_CONFIG_FILENAME);
return async function devToolsConfigMiddlewareHandler(req, res, next) {
const { pathname } = new URL(`http://n${req.url}`);
if (pathname !== DEVTOOLS_CONFIG_MIDDLEWARE_ENDPOINT) {
return next();
}
if (req.method !== 'POST') {
return middlewareResponse.methodNotAllowed(res);
}
const currentConfig = await getDevToolsConfig(distDir);
const chunks = [];
for await (const chunk of req){
chunks.push(Buffer.from(chunk));
}
let body = Buffer.concat(chunks).toString('utf8');
try {
body = JSON.parse(body);
} catch (error) {
console.error('[Next.js DevTools] Invalid config body passed:', error);
return middlewareResponse.badRequest(res);
}
const validation = devToolsConfigSchema.safeParse(body);
if (!validation.success) {
console.error('[Next.js DevTools] Invalid config passed:', validation.error.message);
return middlewareResponse.badRequest(res);
}
const newConfig = deepMerge(currentConfig, validation.data);
await writeFile(configPath, JSON.stringify(newConfig, null, 2));
sendUpdateSignal(newConfig);
return middlewareResponse.noContent(res);
};
}
export async function getDevToolsConfig(distDir) {
const configPath = join(distDir, 'cache', DEVTOOLS_CONFIG_FILENAME);
if (!existsSync(configPath)) {
await mkdir(dirname(configPath), {
recursive: true
});
await writeFile(configPath, JSON.stringify({}));
return {};
}
return JSON.parse(await readFile(configPath, 'utf8'));
}
//# sourceMappingURL=devtools-config-middleware.js.map