feat: add GET /profiles route

This commit is contained in:
2026-08-12 21:29:47 +08:00
parent e79590a6d8
commit 452581c3b5
2 changed files with 16 additions and 1 deletions
+14
View File
@@ -0,0 +1,14 @@
// Profiles API route — list available fingerprint profiles / 指纹配置 API 路由
import type { IncomingMessage, ServerResponse } from 'node:http';
import { listProfiles } from '../stealth/index.js';
export function profilesRoute(req: IncomingMessage, res: ServerResponse): boolean {
const url = new URL(req.url || '/', 'http://localhost');
if (req.method === 'GET' && url.pathname === '/profiles') {
const data = listProfiles();
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ ok: true, data }));
return true;
}
return false;
}
+2 -1
View File
@@ -3,11 +3,12 @@ import { healthRoute } from './routes/health.js';
import { pageRoutes } from './routes/pages.js'; import { pageRoutes } from './routes/pages.js';
import { contentRoutes } from './routes/content.js'; import { contentRoutes } from './routes/content.js';
import { actionRoutes } from './routes/actions.js'; import { actionRoutes } from './routes/actions.js';
import { profilesRoute } from './routes/profiles.js';
import type { BrowserManager } from './browser-manager.js'; import type { BrowserManager } from './browser-manager.js';
import { createWsRelay } from './ws-relay.js'; import { createWsRelay } from './ws-relay.js';
export function startServer(port: number, browserManager?: BrowserManager): Promise<http.Server> { export function startServer(port: number, browserManager?: BrowserManager): Promise<http.Server> {
const routes = [healthRoute]; const routes = [healthRoute, profilesRoute];
if (browserManager) { if (browserManager) {
routes.push(pageRoutes(browserManager)); routes.push(pageRoutes(browserManager));
routes.push(contentRoutes(browserManager)); routes.push(contentRoutes(browserManager));