Files
ONE-OS/axhub-make/vite-plugins/virtualHtml/handlers/hackCssHandler.ts
王冕 a27e3b8e43 feat: sync full workspace including web modules, docs, and configurations to Gitea
Optimized the root .gitignore to exclude virtual environments, node modules,
and temp folders to ensure clean and lightweight version tracking.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-09 18:12:25 +08:00

34 lines
1.2 KiB
TypeScript

import type { IncomingMessage, ServerResponse } from 'http';
import fs from 'fs';
import path from 'path';
export function handleHackCssRequest(req: IncomingMessage, res: ServerResponse): boolean {
const requestPath = req.url ? req.url.split('?')[0] : '';
if (req.method === 'GET' && requestPath.endsWith('/hack.css')) {
const decodedRequestPath = decodeURIComponent(requestPath);
const pathParts = decodedRequestPath.split('/').filter(Boolean);
if (pathParts.length >= 2 && ['components', 'prototypes'].includes(pathParts[0])) {
const hackCssPath = path.resolve(process.cwd(), 'src', decodedRequestPath.slice(1));
if (fs.existsSync(hackCssPath)) {
try {
let css = fs.readFileSync(hackCssPath, 'utf8');
css = css.replace(/\/\*\s*@ai-agent-warning:.*?\*\/\s*/g, '');
res.statusCode = 200;
res.setHeader('Content-Type', 'text/css; charset=utf-8');
res.end(css);
return true;
} catch (err) {
console.error('[API] 读取 hack.css 失败:', hackCssPath, err);
}
} else {
console.warn('[API] hack.css 不存在:', hackCssPath);
}
}
}
return false;
}