http-static-router.d.ts 963 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {ServerResponse} from 'node:http';
  2. import {IncomingMessage} from 'node:http';
  3. import {DebuggableService, ServiceContainer} from '@e22m4u/js-service';
  4. /**
  5. * Static file route.
  6. */
  7. export type HttpStaticRoute = {
  8. remotePath: string;
  9. resourcePath: string;
  10. regexp: RegExp;
  11. isFile: boolean;
  12. };
  13. /**
  14. * Http static router.
  15. */
  16. export class HttpStaticRouter extends DebuggableService {
  17. /**
  18. * Constructor.
  19. *
  20. * @param container
  21. */
  22. constructor(container?: ServiceContainer);
  23. /**
  24. * Add route.
  25. *
  26. * @param remotePath
  27. * @param resourcePath
  28. */
  29. addRoute(remotePath: string, resourcePath: string): this;
  30. /**
  31. * Match route.
  32. *
  33. * @param req
  34. */
  35. matchRoute(req: IncomingMessage): HttpStaticRoute | undefined;
  36. /**
  37. * Send file by route.
  38. *
  39. * @param route
  40. * @param req
  41. * @param res
  42. */
  43. sendFileByRoute(
  44. route: HttpStaticRoute,
  45. req: IncomingMessage,
  46. res: ServerResponse,
  47. ): void;
  48. }