Files
typedserver/ts/controllers/controller.typedrequest.ts
Juergen Kunz c17d6dac35 feat: Refactor TypedServer to use SmartServe and introduce new request handlers
- Removed legacy servertools and Express dependencies in favor of SmartServe.
- Introduced DevToolsHandler and TypedRequestHandler for handling specific routes.
- Added support for custom route registration with regex parsing.
- Implemented sitemap and feed handling with dedicated helper classes.
- Enhanced HTML response handling with reload script injection.
- Updated UtilityServiceServer and UtilityWebsiteServer to utilize new TypedServer API.
- Removed deprecated compression options and Express-based route handling.
- Added comprehensive request handling for various endpoints including robots.txt, manifest.json, and sitemap.
- Improved error handling and response formatting across the server.
2025-12-02 20:26:34 +00:00

44 lines
1.1 KiB
TypeScript

import * as plugins from '../plugins.js';
/**
* TypedRequest handler for type-safe RPC endpoint
*/
export class TypedRequestHandler {
private typedRouter: plugins.typedrequest.TypedRouter;
constructor(typedRouter: plugins.typedrequest.TypedRouter) {
this.typedRouter = typedRouter;
}
/**
* Handle a request - returns Response if handled, null otherwise
*/
public async handle(request: Request): Promise<Response | null> {
const url = new URL(request.url);
const path = url.pathname;
if (path === '/typedrequest' && request.method === 'POST') {
try {
const body = await request.json();
const response = await this.typedRouter.routeAndAddResponse(body);
return new Response(plugins.smartjson.stringify(response), {
status: 200,
headers: {
'Content-Type': 'application/json',
},
});
} catch (error) {
return new Response(JSON.stringify({ error: 'Invalid request' }), {
status: 400,
headers: {
'Content-Type': 'application/json',
},
});
}
}
return null;
}
}