@adaas/a-server 0.0.22 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.conf/tsconfig.base.json +79 -0
- package/.conf/tsconfig.browser.json +32 -0
- package/.conf/tsconfig.node.json +33 -0
- package/LICENSE +10 -19
- package/dist/browser/index.d.mts +1699 -0
- package/dist/browser/index.mjs +2935 -0
- package/dist/browser/index.mjs.map +1 -0
- package/dist/node/A-Request.entity-8_9MCXT2.d.ts +533 -0
- package/dist/node/A-Request.entity-r905O60G.d.mts +533 -0
- package/dist/node/A-Response.entity-6qhiV7BE.d.mts +348 -0
- package/dist/node/A-Response.entity-bjh6bofZ.d.ts +348 -0
- package/dist/node/channels/A-Http/A-Http.channel.constants.d.mts +9 -0
- package/dist/node/channels/A-Http/A-Http.channel.constants.d.ts +9 -0
- package/dist/node/channels/A-Http/A-Http.channel.constants.js +13 -0
- package/dist/node/channels/A-Http/A-Http.channel.constants.js.map +1 -0
- package/dist/node/channels/A-Http/A-Http.channel.constants.mjs +12 -0
- package/dist/node/channels/A-Http/A-Http.channel.constants.mjs.map +1 -0
- package/dist/node/channels/A-Http/A-Http.channel.d.mts +23 -0
- package/dist/node/channels/A-Http/A-Http.channel.d.ts +23 -0
- package/dist/node/channels/A-Http/A-Http.channel.error.d.mts +7 -0
- package/dist/node/channels/A-Http/A-Http.channel.error.d.ts +7 -0
- package/dist/node/channels/A-Http/A-Http.channel.error.js +11 -0
- package/dist/node/channels/A-Http/A-Http.channel.error.js.map +1 -0
- package/dist/node/channels/A-Http/A-Http.channel.error.mjs +10 -0
- package/dist/node/channels/A-Http/A-Http.channel.error.mjs.map +1 -0
- package/dist/node/channels/A-Http/A-Http.channel.js +122 -0
- package/dist/node/channels/A-Http/A-Http.channel.js.map +1 -0
- package/dist/node/channels/A-Http/A-Http.channel.mjs +110 -0
- package/dist/node/channels/A-Http/A-Http.channel.mjs.map +1 -0
- package/dist/node/channels/A-Http/A-Http.channel.types.d.mts +67 -0
- package/dist/node/channels/A-Http/A-Http.channel.types.d.ts +67 -0
- package/dist/node/channels/A-Http/A-Http.channel.types.js +4 -0
- package/dist/node/channels/A-Http/A-Http.channel.types.js.map +1 -0
- package/dist/node/channels/A-Http/A-Http.channel.types.mjs +3 -0
- package/dist/node/channels/A-Http/A-Http.channel.types.mjs.map +1 -0
- package/dist/node/channels/A-Websockets/A-Websockets.channel.d.mts +7 -0
- package/dist/node/channels/A-Websockets/A-Websockets.channel.d.ts +7 -0
- package/dist/node/channels/A-Websockets/A-Websockets.channel.js +13 -0
- package/dist/node/channels/A-Websockets/A-Websockets.channel.js.map +1 -0
- package/dist/node/channels/A-Websockets/A-Websockets.channel.mjs +12 -0
- package/dist/node/channels/A-Websockets/A-Websockets.channel.mjs.map +1 -0
- package/dist/node/chunk-EQQGB2QZ.mjs +15 -0
- package/dist/node/chunk-EQQGB2QZ.mjs.map +1 -0
- package/dist/node/constants/env.constants.d.mts +12 -0
- package/dist/node/constants/env.constants.d.ts +12 -0
- package/dist/node/constants/env.constants.js +23 -0
- package/dist/node/constants/env.constants.js.map +1 -0
- package/dist/node/constants/env.constants.mjs +22 -0
- package/dist/node/constants/env.constants.mjs.map +1 -0
- package/dist/node/controllers/A-CommandController/A-CommandController.component.d.mts +29 -0
- package/dist/node/controllers/A-CommandController/A-CommandController.component.d.ts +29 -0
- package/dist/node/controllers/A-CommandController/A-CommandController.component.js +55 -0
- package/dist/node/controllers/A-CommandController/A-CommandController.component.js.map +1 -0
- package/dist/node/controllers/A-CommandController/A-CommandController.component.mjs +43 -0
- package/dist/node/controllers/A-CommandController/A-CommandController.component.mjs.map +1 -0
- package/dist/node/controllers/A-EntityController/A-EntityController.component.d.mts +44 -0
- package/dist/node/controllers/A-EntityController/A-EntityController.component.d.ts +44 -0
- package/dist/node/controllers/A-EntityController/A-EntityController.component.js +189 -0
- package/dist/node/controllers/A-EntityController/A-EntityController.component.js.map +1 -0
- package/dist/node/controllers/A-EntityController/A-EntityController.component.mjs +177 -0
- package/dist/node/controllers/A-EntityController/A-EntityController.component.mjs.map +1 -0
- package/dist/node/controllers/A-EntityController/A-EntityController.component.types.d.mts +2 -0
- package/dist/node/controllers/A-EntityController/A-EntityController.component.types.d.ts +2 -0
- package/dist/node/controllers/A-EntityController/A-EntityController.component.types.js +4 -0
- package/dist/node/controllers/A-EntityController/A-EntityController.component.types.js.map +1 -0
- package/dist/node/controllers/A-EntityController/A-EntityController.component.types.mjs +3 -0
- package/dist/node/controllers/A-EntityController/A-EntityController.component.types.mjs.map +1 -0
- package/dist/node/controllers/A-ListingController/A-ListingController.component.d.mts +28 -0
- package/dist/node/controllers/A-ListingController/A-ListingController.component.d.ts +28 -0
- package/dist/node/controllers/A-ListingController/A-ListingController.component.js +59 -0
- package/dist/node/controllers/A-ListingController/A-ListingController.component.js.map +1 -0
- package/dist/node/controllers/A-ListingController/A-ListingController.component.mjs +47 -0
- package/dist/node/controllers/A-ListingController/A-ListingController.component.mjs.map +1 -0
- package/dist/node/controllers/A-ListingController/A-ListingController.types.d.mts +2 -0
- package/dist/node/controllers/A-ListingController/A-ListingController.types.d.ts +2 -0
- package/dist/node/controllers/A-ListingController/A-ListingController.types.js +4 -0
- package/dist/node/controllers/A-ListingController/A-ListingController.types.js.map +1 -0
- package/dist/node/controllers/A-ListingController/A-ListingController.types.mjs +3 -0
- package/dist/node/controllers/A-ListingController/A-ListingController.types.mjs.map +1 -0
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.d.mts +30 -0
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.d.ts +30 -0
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.js +46 -0
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.js.map +1 -0
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.mjs +34 -0
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.mjs.map +1 -0
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.d.mts +2 -0
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.d.ts +2 -0
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.js +4 -0
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.js.map +1 -0
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.mjs +3 -0
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.mjs.map +1 -0
- package/dist/node/index.d.mts +51 -0
- package/dist/node/index.d.ts +51 -0
- package/dist/node/index.js +320 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/index.mjs +48 -0
- package/dist/node/index.mjs.map +1 -0
- package/dist/node/lib/A-Request/A-HttpRequestData.context.d.mts +12 -0
- package/dist/node/lib/A-Request/A-HttpRequestData.context.d.ts +12 -0
- package/dist/node/lib/A-Request/A-HttpRequestData.context.js +25 -0
- package/dist/node/lib/A-Request/A-HttpRequestData.context.js.map +1 -0
- package/dist/node/lib/A-Request/A-HttpRequestData.context.mjs +24 -0
- package/dist/node/lib/A-Request/A-HttpRequestData.context.mjs.map +1 -0
- package/dist/node/lib/A-Request/A-HttpServerRequest.context.d.mts +39 -0
- package/dist/node/lib/A-Request/A-HttpServerRequest.context.d.ts +39 -0
- package/dist/node/lib/A-Request/A-HttpServerRequest.context.js +56 -0
- package/dist/node/lib/A-Request/A-HttpServerRequest.context.js.map +1 -0
- package/dist/node/lib/A-Request/A-HttpServerRequest.context.mjs +55 -0
- package/dist/node/lib/A-Request/A-HttpServerRequest.context.mjs.map +1 -0
- package/dist/node/lib/A-Request/A-Request.constants.d.mts +18 -0
- package/dist/node/lib/A-Request/A-Request.constants.d.ts +18 -0
- package/dist/node/lib/A-Request/A-Request.constants.js +22 -0
- package/dist/node/lib/A-Request/A-Request.constants.js.map +1 -0
- package/dist/node/lib/A-Request/A-Request.constants.mjs +22 -0
- package/dist/node/lib/A-Request/A-Request.constants.mjs.map +1 -0
- package/dist/node/lib/A-Request/A-Request.entity.d.mts +17 -0
- package/dist/node/lib/A-Request/A-Request.entity.d.ts +17 -0
- package/dist/node/lib/A-Request/A-Request.entity.js +651 -0
- package/dist/node/lib/A-Request/A-Request.entity.js.map +1 -0
- package/dist/node/lib/A-Request/A-Request.entity.mjs +639 -0
- package/dist/node/lib/A-Request/A-Request.entity.mjs.map +1 -0
- package/dist/node/lib/A-Request/A-Request.env.d.mts +37 -0
- package/dist/node/lib/A-Request/A-Request.env.d.ts +37 -0
- package/dist/node/lib/A-Request/A-Request.env.js +39 -0
- package/dist/node/lib/A-Request/A-Request.env.js.map +1 -0
- package/dist/node/lib/A-Request/A-Request.env.mjs +38 -0
- package/dist/node/lib/A-Request/A-Request.env.mjs.map +1 -0
- package/dist/node/lib/A-Request/A-Request.error.d.mts +11 -0
- package/dist/node/lib/A-Request/A-Request.error.d.ts +11 -0
- package/dist/node/lib/A-Request/A-Request.error.js +15 -0
- package/dist/node/lib/A-Request/A-Request.error.js.map +1 -0
- package/dist/node/lib/A-Request/A-Request.error.mjs +14 -0
- package/dist/node/lib/A-Request/A-Request.error.mjs.map +1 -0
- package/dist/node/lib/A-Request/A-Request.helper.d.mts +105 -0
- package/dist/node/lib/A-Request/A-Request.helper.d.ts +105 -0
- package/dist/node/lib/A-Request/A-Request.helper.js +181 -0
- package/dist/node/lib/A-Request/A-Request.helper.js.map +1 -0
- package/dist/node/lib/A-Request/A-Request.helper.mjs +180 -0
- package/dist/node/lib/A-Request/A-Request.helper.mjs.map +1 -0
- package/dist/node/lib/A-Request/A-Request.types.d.mts +17 -0
- package/dist/node/lib/A-Request/A-Request.types.d.ts +17 -0
- package/dist/node/lib/A-Request/A-Request.types.js +14 -0
- package/dist/node/lib/A-Request/A-Request.types.js.map +1 -0
- package/dist/node/lib/A-Request/A-Request.types.mjs +14 -0
- package/dist/node/lib/A-Request/A-Request.types.mjs.map +1 -0
- package/dist/node/lib/A-Response/A-Response.constants.d.mts +24 -0
- package/dist/node/lib/A-Response/A-Response.constants.d.ts +24 -0
- package/dist/node/lib/A-Response/A-Response.constants.js +28 -0
- package/dist/node/lib/A-Response/A-Response.constants.js.map +1 -0
- package/dist/node/lib/A-Response/A-Response.constants.mjs +28 -0
- package/dist/node/lib/A-Response/A-Response.constants.mjs.map +1 -0
- package/dist/node/lib/A-Response/A-Response.entity.d.mts +20 -0
- package/dist/node/lib/A-Response/A-Response.entity.d.ts +20 -0
- package/dist/node/lib/A-Response/A-Response.entity.js +608 -0
- package/dist/node/lib/A-Response/A-Response.entity.js.map +1 -0
- package/dist/node/lib/A-Response/A-Response.entity.mjs +596 -0
- package/dist/node/lib/A-Response/A-Response.entity.mjs.map +1 -0
- package/dist/node/lib/A-Response/A-Response.env.d.mts +2 -0
- package/dist/node/lib/A-Response/A-Response.env.d.ts +2 -0
- package/dist/node/lib/A-Response/A-Response.env.js +4 -0
- package/dist/node/lib/A-Response/A-Response.env.js.map +1 -0
- package/dist/node/lib/A-Response/A-Response.env.mjs +3 -0
- package/dist/node/lib/A-Response/A-Response.env.mjs.map +1 -0
- package/dist/node/lib/A-Response/A-Response.error.d.mts +6 -0
- package/dist/node/lib/A-Response/A-Response.error.d.ts +6 -0
- package/dist/node/lib/A-Response/A-Response.error.js +10 -0
- package/dist/node/lib/A-Response/A-Response.error.js.map +1 -0
- package/dist/node/lib/A-Response/A-Response.error.mjs +9 -0
- package/dist/node/lib/A-Response/A-Response.error.mjs.map +1 -0
- package/dist/node/lib/A-Response/A-Response.types.d.mts +20 -0
- package/dist/node/lib/A-Response/A-Response.types.d.ts +20 -0
- package/dist/node/lib/A-Response/A-Response.types.js +4 -0
- package/dist/node/lib/A-Response/A-Response.types.js.map +1 -0
- package/dist/node/lib/A-Response/A-Response.types.mjs +3 -0
- package/dist/node/lib/A-Response/A-Response.types.mjs.map +1 -0
- package/dist/node/lib/A-Server/A-HttpServer.constants.d.mts +7 -0
- package/dist/node/lib/A-Server/A-HttpServer.constants.d.ts +7 -0
- package/dist/node/lib/A-Server/A-HttpServer.constants.js +11 -0
- package/dist/node/lib/A-Server/A-HttpServer.constants.js.map +1 -0
- package/dist/node/lib/A-Server/A-HttpServer.constants.mjs +11 -0
- package/dist/node/lib/A-Server/A-HttpServer.constants.mjs.map +1 -0
- package/dist/node/lib/A-Server/A-HttpServer.container.d.mts +50 -0
- package/dist/node/lib/A-Server/A-HttpServer.container.d.ts +50 -0
- package/dist/node/lib/A-Server/A-HttpServer.container.js +196 -0
- package/dist/node/lib/A-Server/A-HttpServer.container.js.map +1 -0
- package/dist/node/lib/A-Server/A-HttpServer.container.mjs +184 -0
- package/dist/node/lib/A-Server/A-HttpServer.container.mjs.map +1 -0
- package/dist/node/lib/A-Server/A-HttpServer.error.d.mts +54 -0
- package/dist/node/lib/A-Server/A-HttpServer.error.d.ts +54 -0
- package/dist/node/lib/A-Server/A-HttpServer.error.js +118 -0
- package/dist/node/lib/A-Server/A-HttpServer.error.js.map +1 -0
- package/dist/node/lib/A-Server/A-HttpServer.error.mjs +117 -0
- package/dist/node/lib/A-Server/A-HttpServer.error.mjs.map +1 -0
- package/dist/node/lib/A-Server/A-HttpServer.types.d.mts +19 -0
- package/dist/node/lib/A-Server/A-HttpServer.types.d.ts +19 -0
- package/dist/node/lib/A-Server/A-HttpServer.types.js +4 -0
- package/dist/node/lib/A-Server/A-HttpServer.types.js.map +1 -0
- package/dist/node/lib/A-Server/A-HttpServer.types.mjs +3 -0
- package/dist/node/lib/A-Server/A-HttpServer.types.mjs.map +1 -0
- package/dist/node/lib/A-Server/A-Server.context.d.mts +22 -0
- package/dist/node/lib/A-Server/A-Server.context.d.ts +22 -0
- package/dist/node/lib/A-Server/A-Server.context.js +24 -0
- package/dist/node/lib/A-Server/A-Server.context.js.map +1 -0
- package/dist/node/lib/A-Server/A-Server.context.mjs +23 -0
- package/dist/node/lib/A-Server/A-Server.context.mjs.map +1 -0
- package/dist/node/lib/A-Server/A-Server.error.d.mts +14 -0
- package/dist/node/lib/A-Server/A-Server.error.d.ts +14 -0
- package/dist/node/lib/A-Server/A-Server.error.js +26 -0
- package/dist/node/lib/A-Server/A-Server.error.js.map +1 -0
- package/dist/node/lib/A-Server/A-Server.error.mjs +25 -0
- package/dist/node/lib/A-Server/A-Server.error.mjs.map +1 -0
- package/dist/node/lib/A-Server/A-Server.types.d.mts +26 -0
- package/dist/node/lib/A-Server/A-Server.types.d.ts +26 -0
- package/dist/node/lib/A-Server/A-Server.types.js +4 -0
- package/dist/node/lib/A-Server/A-Server.types.js.map +1 -0
- package/dist/node/lib/A-Server/A-Server.types.mjs +3 -0
- package/dist/node/lib/A-Server/A-Server.types.mjs.map +1 -0
- package/dist/node/lib/A-ServerController/A-ServerController.component.d.mts +29 -0
- package/dist/node/lib/A-ServerController/A-ServerController.component.d.ts +29 -0
- package/dist/node/lib/A-ServerController/A-ServerController.component.js +49 -0
- package/dist/node/lib/A-ServerController/A-ServerController.component.js.map +1 -0
- package/dist/node/lib/A-ServerController/A-ServerController.component.mjs +37 -0
- package/dist/node/lib/A-ServerController/A-ServerController.component.mjs.map +1 -0
- package/dist/node/lib/A-ServerController/A-ServerController.types.d.mts +2 -0
- package/dist/node/lib/A-ServerController/A-ServerController.types.d.ts +2 -0
- package/dist/node/lib/A-ServerController/A-ServerController.types.js +4 -0
- package/dist/node/lib/A-ServerController/A-ServerController.types.js.map +1 -0
- package/dist/node/lib/A-ServerController/A-ServerController.types.mjs +3 -0
- package/dist/node/lib/A-ServerController/A-ServerController.types.mjs.map +1 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.d.mts +49 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.d.ts +49 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.js +91 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.js.map +1 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.mjs +90 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.mjs.map +1 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityList.types.d.mts +22 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityList.types.d.ts +22 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityList.types.js +10 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityList.types.js.map +1 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityList.types.mjs +10 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityList.types.mjs.map +1 -0
- package/dist/node/lib/A-ServerListQuery/A-ServerListQueryFilter.context.d.mts +13 -0
- package/dist/node/lib/A-ServerListQuery/A-ServerListQueryFilter.context.d.ts +13 -0
- package/dist/node/lib/A-ServerListQuery/A-ServerListQueryFilter.context.js +32 -0
- package/dist/node/lib/A-ServerListQuery/A-ServerListQueryFilter.context.js.map +1 -0
- package/dist/node/lib/A-ServerListQuery/A-ServerListQueryFilter.context.mjs +31 -0
- package/dist/node/lib/A-ServerListQuery/A-ServerListQueryFilter.context.mjs.map +1 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.d.mts +48 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.d.ts +48 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.js +88 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.js.map +1 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.mjs +76 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.mjs.map +1 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.constants.d.mts +24 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.constants.d.ts +24 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.constants.js +33 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.constants.js.map +1 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.constants.mjs +33 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.constants.mjs.map +1 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.types.d.mts +12 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.types.d.ts +12 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.types.js +4 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.types.js.map +1 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.types.mjs +3 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.types.mjs.map +1 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.component.d.mts +6 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.component.d.ts +6 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.component.js +18 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.component.js.map +1 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.component.mjs +17 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.component.mjs.map +1 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.constants.d.mts +2 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.constants.d.ts +2 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.constants.js +4 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.constants.js.map +1 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.constants.mjs +3 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.constants.mjs.map +1 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.types.d.mts +2 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.types.d.ts +2 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.types.js +4 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.types.js.map +1 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.types.mjs +3 -0
- package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.types.mjs.map +1 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.d.mts +31 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.d.ts +31 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.js +90 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.js.map +1 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.mjs +78 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.mjs.map +1 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.constants.d.mts +9 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.constants.d.ts +9 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.constants.js +14 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.constants.js.map +1 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.constants.mjs +14 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.constants.mjs.map +1 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.context.d.mts +36 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.context.d.ts +36 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.context.js +60 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.context.js.map +1 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.context.mjs +59 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.context.mjs.map +1 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.types.d.mts +23 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.types.d.ts +23 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.types.js +4 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.types.js.map +1 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.types.mjs +3 -0
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.types.mjs.map +1 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.constants.d.mts +20 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.constants.d.ts +20 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.constants.js +25 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.constants.js.map +1 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.constants.mjs +24 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.constants.mjs.map +1 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.entity.d.mts +15 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.entity.d.ts +15 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.entity.js +24 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.entity.js.map +1 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.entity.mjs +23 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.entity.mjs.map +1 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.types.d.mts +6 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.types.d.ts +6 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.types.js +4 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.types.js.map +1 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.types.mjs +3 -0
- package/dist/node/lib/A-ServerRoute/A-ServerRoute.types.mjs.map +1 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.d.mts +84 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.d.ts +84 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.js +194 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.js.map +1 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.mjs +184 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.mjs.map +1 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.constants.d.mts +6 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.constants.d.ts +6 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.constants.js +10 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.constants.js.map +1 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.constants.mjs +10 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.constants.mjs.map +1 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.meta.d.mts +16 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.meta.d.ts +16 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.meta.js +40 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.meta.js.map +1 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.meta.mjs +39 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.meta.mjs.map +1 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.types.d.mts +24 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.types.d.ts +24 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.types.js +4 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.types.js.map +1 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.types.mjs +3 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.types.mjs.map +1 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouterDefine.decorator.d.mts +16 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouterDefine.decorator.d.ts +16 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouterDefine.decorator.js +25 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouterDefine.decorator.js.map +1 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouterDefine.decorator.mjs +24 -0
- package/dist/node/lib/A-ServerRouter/A-ServerRouterDefine.decorator.mjs.map +1 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.d.mts +65 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.d.ts +65 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.js +260 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.js.map +1 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.mjs +248 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.mjs.map +1 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.context.d.mts +110 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.context.d.ts +110 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.context.js +180 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.context.js.map +1 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.context.mjs +179 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.context.mjs.map +1 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.types.d.mts +8 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.types.d.ts +8 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.types.js +4 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.types.js.map +1 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.types.mjs +3 -0
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.types.mjs.map +1 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.d.mts +29 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.d.ts +29 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.js +62 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.js.map +1 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.mjs +50 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.mjs.map +1 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.constants.d.mts +5 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.constants.d.ts +5 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.constants.js +14 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.constants.js.map +1 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.constants.mjs +14 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.constants.mjs.map +1 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.types.d.mts +9 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.types.d.ts +9 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.types.js +4 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.types.js.map +1 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.types.mjs +3 -0
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.types.mjs.map +1 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.d.mts +24 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.d.ts +24 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.js +94 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.js.map +1 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.mjs +82 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.mjs.map +1 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.error.d.mts +2 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.error.d.ts +2 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.error.js +4 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.error.js.map +1 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.error.mjs +3 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.error.mjs.map +1 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.types.d.mts +2 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.types.d.ts +2 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.types.js +4 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.types.js.map +1 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.types.mjs +3 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.types.mjs.map +1 -0
- package/examples/simple-server/commands/SignIn.command.ts +17 -1
- package/examples/simple-server/components/Test.controller.ts +8 -7
- package/examples/simple-server/components/Users.repository.ts +28 -26
- package/examples/simple-server/concept.ts +56 -66
- package/examples/simple-server/entities/User/User.entity.ts +17 -7
- package/jest.config.ts +24 -10
- package/package.json +267 -25
- package/src/channels/A-Http/A-Http.channel.constants.ts +6 -7
- package/src/channels/A-Http/A-Http.channel.error.ts +2 -2
- package/src/channels/A-Http/A-Http.channel.ts +76 -125
- package/src/channels/A-Http/A-Http.channel.types.ts +6 -3
- package/src/channels/A-Websockets/A-Websockets.channel.ts +1 -1
- package/src/{components → controllers}/A-CommandController/A-CommandController.component.ts +16 -10
- package/src/{components → controllers}/A-EntityController/A-EntityController.component.ts +24 -28
- package/src/{components → controllers}/A-ListingController/A-ListingController.component.ts +10 -12
- package/src/{components → controllers}/A-ServerHealthMonitor/A-ServerHealthMonitor.component.ts +11 -11
- package/src/index.ts +58 -63
- package/src/lib/A-Request/A-HttpRequestData.context.ts +30 -0
- package/src/lib/A-Request/A-HttpServerRequest.context.ts +103 -0
- package/src/lib/A-Request/A-Request.constants.ts +30 -0
- package/src/lib/A-Request/A-Request.entity.ts +844 -0
- package/src/lib/A-Request/A-Request.env.ts +50 -0
- package/src/lib/A-Request/A-Request.error.ts +11 -0
- package/src/lib/A-Request/A-Request.helper.ts +276 -0
- package/src/lib/A-Request/A-Request.types.ts +284 -0
- package/src/lib/A-Request/README.md +567 -0
- package/src/lib/A-Response/A-Response.constants.ts +24 -0
- package/src/lib/A-Response/A-Response.entity.ts +751 -0
- package/src/lib/A-Response/A-Response.error.ts +6 -0
- package/src/lib/A-Response/A-Response.types.ts +127 -0
- package/src/lib/A-Response/README.md +793 -0
- package/src/lib/A-Server/A-HttpServer.constants.ts +9 -0
- package/src/lib/A-Server/A-HttpServer.container.ts +256 -0
- package/src/lib/A-Server/A-HttpServer.error.ts +165 -0
- package/src/lib/A-Server/A-HttpServer.types.ts +37 -0
- package/src/{context/A-Server/A_Server.context.ts → lib/A-Server/A-Server.context.ts} +6 -7
- package/src/lib/A-Server/A-Server.error.ts +26 -0
- package/src/{components/A-ServerError/A-ServerError.types.ts → lib/A-Server/A-Server.types.ts} +8 -0
- package/src/{components/A-Controller/A-Controller.component.ts → lib/A-ServerController/A-ServerController.component.ts} +5 -5
- package/src/{entities/A_EntityList/A_EntityList.entity.ts → lib/A-ServerEntityList/A-EntityList.entity.ts} +2 -2
- package/src/{entities/A_EntityList/A_EntityList.entity.types.ts → lib/A-ServerEntityList/A-EntityList.types.ts} +2 -2
- package/src/{context/A-ListQueryFilter/A_ListQueryFilter.context.ts → lib/A-ServerListQuery/A-ServerListQueryFilter.context.ts} +1 -1
- package/src/lib/A-ServerLogger/A-ServerLogger.component.ts +121 -0
- package/src/lib/A-ServerLogger/A-ServerLogger.types.ts +13 -0
- package/src/lib/A-ServerMiddleware/A-ServerMiddleware.component.ts +17 -0
- package/src/{components → lib}/A-ServerProxy/A-ServerProxy.component.ts +17 -12
- package/src/{context/A-ProxyConfig/A_ProxyConfig.constants.ts → lib/A-ServerProxy/A-ServerProxy.constants.ts} +1 -1
- package/src/{context/A-ProxyConfig/A_ProxyConfig.context.ts → lib/A-ServerProxy/A-ServerProxy.context.ts} +4 -4
- package/src/{context/A-ProxyConfig/A_ProxyConfig.types.ts → lib/A-ServerProxy/A-ServerProxy.types.ts} +4 -4
- package/src/lib/A-ServerRoute/A-ServerRoute.constants.ts +20 -0
- package/src/lib/A-ServerRoute/A-ServerRoute.entity.ts +48 -0
- package/src/lib/A-ServerRoute/A-ServerRoute.types.ts +6 -0
- package/src/{components/A-Router/A-Router.component.ts → lib/A-ServerRouter/A-ServerRouter.component.ts} +77 -97
- package/src/lib/A-ServerRouter/A-ServerRouter.constants.ts +8 -0
- package/src/lib/A-ServerRouter/A-ServerRouter.meta.ts +48 -0
- package/src/lib/A-ServerRouter/A-ServerRouter.types.ts +27 -0
- package/src/lib/A-ServerRouter/A-ServerRouterDefine.decorator.ts +37 -0
- package/src/{components/A-StaticLoader/A-StaticLoader.component.ts → lib/A-ServerStatic/A-ServerStatic.component.ts} +73 -54
- package/src/{context/A-StaticConfig/A-StaticConfig.context.ts → lib/A-ServerStatic/A-ServerStatic.context.ts} +16 -6
- package/src/{components → middlewares}/A-ServerCORS/A_ServerCORS.component.ts +16 -13
- package/src/{components/A-ServerCORS/A_ServerCORS.component.defaults.ts → middlewares/A-ServerCORS/A_ServerCORS.constants.ts} +2 -2
- package/src/{components → repositories}/A-EntityRepository/A-EntityRepository.component.ts +39 -30
- package/tests/A-HttpChannel.test.ts +41 -48
- package/tests/A-HttpServerError.test.ts +204 -0
- package/tests/A-Request.test.ts +351 -0
- package/tsconfig.json +40 -50
- package/tsup.config.ts +111 -13
- package/dist/index.d.mts +0 -855
- package/dist/index.d.ts +0 -855
- package/dist/index.js +0 -2179
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -2144
- package/dist/index.mjs.map +0 -1
- package/examples/microservices-server/components/controllers/Statistics.controller.ts +0 -18
- package/examples/microservices-server/components/repositories/Memory.repository.ts +0 -66
- package/examples/microservices-server/concept.ts +0 -43
- package/examples/microservices-server/context/MemoryStore.context.ts +0 -31
- package/examples/microservices-server/entities/Order.entity.ts +0 -7
- package/examples/microservices-server/entities/User.entity.ts +0 -8
- package/src/components/A-Router/A-Router.component.types.ts +0 -38
- package/src/components/A-ServerError/A-ServerError.class.ts +0 -98
- package/src/components/A-ServerLogger/A_ServerLogger.component.ts +0 -194
- package/src/components/A-ServerLogger/A_ServerLogger.component.types.ts +0 -14
- package/src/containers/A-Service/A-Service.container.ts +0 -218
- package/src/containers/A-Service/A-Service.container.types.ts +0 -46
- package/src/context/A-EntityFactory/A-EntityFactory.context.ts +0 -163
- package/src/context/A-EntityFactory/A-EntityFactory.context.types.ts +0 -11
- package/src/context/A-HttpChannel/A-HttpChannel.context.ts +0 -36
- package/src/context/A-Server/A_Server.context.types.ts +0 -9
- package/src/entities/A-Request/A-Request.entity.ts +0 -163
- package/src/entities/A-Request/A-Request.entity.types.ts +0 -41
- package/src/entities/A-Response/A-Response.entity.ts +0 -194
- package/src/entities/A-Response/A-Response.entity.types.ts +0 -26
- package/src/entities/A-Route/A-Route.entity.ts +0 -117
- package/tests/A-Service.test.ts +0 -18
- /package/src/{components → controllers}/A-EntityController/A-EntityController.component.types.ts +0 -0
- /package/src/{components/A-Controller/A-Controller.component.types.ts → controllers/A-ListingController/A-ListingController.types.ts} +0 -0
- /package/src/{components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.types.ts → controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.ts} +0 -0
- /package/src/{components/A-EntityRepository/A-EntityRepository.error.ts → lib/A-Response/A-Response.env.ts} +0 -0
- /package/src/{components/A-EntityRepository/A-EntityRepository.types.ts → lib/A-ServerController/A-ServerController.types.ts} +0 -0
- /package/src/{components → lib}/A-ServerLogger/A-ServerLogger.constants.ts +0 -0
- /package/src/{components/A-ListingController/A-ListingController.component.types.ts → lib/A-ServerMiddleware/A-ServerMiddleware.constants.ts} +0 -0
- /package/src/{components/A-ServerError/A-ServerError.constants.ts → lib/A-ServerMiddleware/A-ServerMiddleware.types.ts} +0 -0
- /package/src/{components/A-StaticLoader/A-StaticLoader.component.types.ts → lib/A-ServerStatic/A-ServerStatic.types.ts} +0 -0
- /package/src/{components/A-ServerCORS/A_ServerCORS.component.types.ts → middlewares/A-ServerCORS/A_ServerCORS.types.ts} +0 -0
- /package/src/{context/A-StaticConfig/A-StaticConfig.context.types.ts → repositories/A-EntityRepository/A-EntityRepository.error.ts} +0 -0
- /package/src/{entities/A-Route/A-Route.entity.types.ts → repositories/A-EntityRepository/A-EntityRepository.types.ts} +0 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var aConcept = require('@adaas/a-concept');
|
|
4
|
+
var ARequest_entity = require('@adaas/a-server/request/A-Request.entity');
|
|
5
|
+
var AResponse_entity = require('@adaas/a-server/response/A-Response.entity');
|
|
6
|
+
var AServerStatic_context = require('./A-ServerStatic.context');
|
|
7
|
+
var AHttpServer_constants = require('@adaas/a-server/server/A-HttpServer.constants');
|
|
8
|
+
var AHttpServer_error = require('@adaas/a-server/server/A-HttpServer.error');
|
|
9
|
+
var aLogger = require('@adaas/a-utils/a-logger');
|
|
10
|
+
var aPolyfill = require('@adaas/a-utils/a-polyfill');
|
|
11
|
+
var AServerRoute_entity = require('@adaas/a-server/route/A-ServerRoute.entity');
|
|
12
|
+
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
16
|
+
var result = __getOwnPropDesc(target, key) ;
|
|
17
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
18
|
+
if (decorator = decorators[i])
|
|
19
|
+
result = (decorator(target, key, result) ) || result;
|
|
20
|
+
if (result) __defProp(target, key, result);
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
24
|
+
var _a;
|
|
25
|
+
class A_StaticLoader extends aConcept.A_Component {
|
|
26
|
+
async load(logger, config, polyfill) {
|
|
27
|
+
this._fsPolyfill = await polyfill.fs();
|
|
28
|
+
this._pathPolyfill = await polyfill.path();
|
|
29
|
+
const aliases = config.getEnabledAliases();
|
|
30
|
+
logger.info(
|
|
31
|
+
"cyan",
|
|
32
|
+
`Static aliases configured:`,
|
|
33
|
+
...aliases.map((alias) => `${alias.alias} -> ${alias.directory}`)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
async [_a = AHttpServer_constants.A_HttpServerFeatures.onRequest](req, res, logger, config, polyfill) {
|
|
37
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const { method, url } = req;
|
|
41
|
+
const route = new AServerRoute_entity.A_ServerRoute(url, method);
|
|
42
|
+
const alias = config.findMatchingAlias(route.path);
|
|
43
|
+
if (!alias) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const fs = this._fsPolyfill || await polyfill.fs();
|
|
48
|
+
const path = this._pathPolyfill || await polyfill.path();
|
|
49
|
+
const staticDir = path.resolve(process.cwd(), alias.directory);
|
|
50
|
+
if (!fs.existsSync(staticDir)) {
|
|
51
|
+
logger.log("red", `Static directory ${staticDir} does not exist.`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const relativePath = route.path.replace(alias.path, "");
|
|
55
|
+
const safePath = this.safeFilePath(staticDir, relativePath, req.headers?.host, path, fs);
|
|
56
|
+
await this.serveFile(safePath, res, logger, fs, path);
|
|
57
|
+
logger.log("green", `Successfully served: ${safePath}`);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new AHttpServer_error.A_HttpServerError({
|
|
60
|
+
status: 500,
|
|
61
|
+
title: "Static File Serving Error",
|
|
62
|
+
description: `Error serving static file for ${route.path}: ${error.message}`,
|
|
63
|
+
originalError: error
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Add a custom static file alias through the config
|
|
69
|
+
* @param alias - The URL path alias (e.g., '/assets')
|
|
70
|
+
* @param directory - The local directory path
|
|
71
|
+
* @param path - Optional custom path (defaults to alias)
|
|
72
|
+
* @param config - Static config instance
|
|
73
|
+
* @param logger - Logger instance for logging
|
|
74
|
+
*/
|
|
75
|
+
addAlias(alias, directory, config, logger, path) {
|
|
76
|
+
config.addAlias(alias, directory, path);
|
|
77
|
+
if (logger) {
|
|
78
|
+
logger.log("cyan", `Static alias added: ${alias} -> ${directory}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Remove a static file alias through the config
|
|
83
|
+
* @param aliasPath - The path of the alias to remove
|
|
84
|
+
* @param config - Static config instance
|
|
85
|
+
* @param logger - Logger instance for logging
|
|
86
|
+
*/
|
|
87
|
+
removeAlias(aliasPath, config, logger) {
|
|
88
|
+
const removed = config.removeAlias(aliasPath);
|
|
89
|
+
if (removed && logger) {
|
|
90
|
+
logger.log("yellow", `Static alias removed: ${aliasPath}`);
|
|
91
|
+
}
|
|
92
|
+
return removed;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get all configured aliases from config
|
|
96
|
+
* @param config - Static config instance
|
|
97
|
+
*/
|
|
98
|
+
getAliases(config) {
|
|
99
|
+
return config.getAliases();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Enable or disable an alias
|
|
103
|
+
* @param aliasPath - The path of the alias
|
|
104
|
+
* @param enabled - Whether to enable or disable
|
|
105
|
+
* @param config - Static config instance
|
|
106
|
+
* @param logger - Logger instance for logging
|
|
107
|
+
*/
|
|
108
|
+
setAliasEnabled(aliasPath, enabled, config, logger) {
|
|
109
|
+
const result = config.setAliasEnabled(aliasPath, enabled);
|
|
110
|
+
if (result && logger) {
|
|
111
|
+
logger.log("blue", `Static alias ${enabled ? "enabled" : "disabled"}: ${aliasPath}`);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
getMimeType(ext) {
|
|
116
|
+
const mimeTypes = {
|
|
117
|
+
// Text
|
|
118
|
+
".html": "text/html",
|
|
119
|
+
".htm": "text/html",
|
|
120
|
+
".css": "text/css",
|
|
121
|
+
".txt": "text/plain",
|
|
122
|
+
".md": "text/markdown",
|
|
123
|
+
".xml": "application/xml",
|
|
124
|
+
// JavaScript
|
|
125
|
+
".js": "application/javascript",
|
|
126
|
+
".mjs": "application/javascript",
|
|
127
|
+
".jsx": "application/javascript",
|
|
128
|
+
".ts": "application/typescript",
|
|
129
|
+
".tsx": "application/typescript",
|
|
130
|
+
// JSON
|
|
131
|
+
".json": "application/json",
|
|
132
|
+
".jsonld": "application/ld+json",
|
|
133
|
+
// Images
|
|
134
|
+
".png": "image/png",
|
|
135
|
+
".jpg": "image/jpeg",
|
|
136
|
+
".jpeg": "image/jpeg",
|
|
137
|
+
".gif": "image/gif",
|
|
138
|
+
".svg": "image/svg+xml",
|
|
139
|
+
".ico": "image/x-icon",
|
|
140
|
+
".webp": "image/webp",
|
|
141
|
+
".bmp": "image/bmp",
|
|
142
|
+
".tiff": "image/tiff",
|
|
143
|
+
// Fonts
|
|
144
|
+
".woff": "font/woff",
|
|
145
|
+
".woff2": "font/woff2",
|
|
146
|
+
".ttf": "font/ttf",
|
|
147
|
+
".otf": "font/otf",
|
|
148
|
+
".eot": "application/vnd.ms-fontobject",
|
|
149
|
+
// Audio/Video
|
|
150
|
+
".mp3": "audio/mpeg",
|
|
151
|
+
".wav": "audio/wav",
|
|
152
|
+
".mp4": "video/mp4",
|
|
153
|
+
".webm": "video/webm",
|
|
154
|
+
".ogg": "application/ogg",
|
|
155
|
+
// Archives
|
|
156
|
+
".zip": "application/zip",
|
|
157
|
+
".tar": "application/x-tar",
|
|
158
|
+
".gz": "application/gzip",
|
|
159
|
+
// Documents
|
|
160
|
+
".pdf": "application/pdf",
|
|
161
|
+
".doc": "application/msword",
|
|
162
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
163
|
+
".xls": "application/vnd.ms-excel",
|
|
164
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
165
|
+
};
|
|
166
|
+
return mimeTypes[ext.toLowerCase()] || "application/octet-stream";
|
|
167
|
+
}
|
|
168
|
+
safeFilePath(staticDir, reqUrl, host = "localhost", pathPolyfill, fsPolyfill) {
|
|
169
|
+
const parsedUrl = new URL(reqUrl || "/", `http://${host}`);
|
|
170
|
+
let pathname = decodeURIComponent(parsedUrl.pathname);
|
|
171
|
+
pathname = pathname.replace(/\.\.[\/\\]/g, "");
|
|
172
|
+
let filePath = pathPolyfill.join(staticDir, pathname);
|
|
173
|
+
if (!fsPolyfill.existsSync(filePath)) {
|
|
174
|
+
throw new Error(`File not found: ${filePath}`);
|
|
175
|
+
}
|
|
176
|
+
return filePath;
|
|
177
|
+
}
|
|
178
|
+
serveFile(filePath, res, logger, fsPolyfill, pathPolyfill) {
|
|
179
|
+
return new Promise((resolve, reject) => {
|
|
180
|
+
try {
|
|
181
|
+
if (fsPolyfill.existsSync(filePath)) {
|
|
182
|
+
const ext = pathPolyfill.extname(filePath);
|
|
183
|
+
const contentType = this.getMimeType(ext);
|
|
184
|
+
const headers = {
|
|
185
|
+
"Content-Type": contentType,
|
|
186
|
+
"Cache-Control": this.getCacheControl(ext),
|
|
187
|
+
"X-Content-Type-Options": "nosniff"
|
|
188
|
+
};
|
|
189
|
+
res.writeHead(200, headers);
|
|
190
|
+
const stream = fsPolyfill.createReadStream(filePath);
|
|
191
|
+
if (stream && res.original) {
|
|
192
|
+
stream.pipe(res.original);
|
|
193
|
+
stream.on("end", () => {
|
|
194
|
+
resolve();
|
|
195
|
+
});
|
|
196
|
+
stream.on("error", (err) => {
|
|
197
|
+
reject(new AHttpServer_error.A_HttpServerError({
|
|
198
|
+
status: 500,
|
|
199
|
+
title: "File Stream Error",
|
|
200
|
+
description: `Error reading file stream for ${filePath}: ${err.message}`,
|
|
201
|
+
originalError: err
|
|
202
|
+
}));
|
|
203
|
+
});
|
|
204
|
+
} else {
|
|
205
|
+
reject(new AHttpServer_error.A_HttpServerError({
|
|
206
|
+
status: 500,
|
|
207
|
+
title: "Response Stream Error",
|
|
208
|
+
description: `Unable to pipe file stream for ${filePath}`
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
reject(new AHttpServer_error.A_HttpServerError({
|
|
213
|
+
status: 404,
|
|
214
|
+
title: "File Not Found",
|
|
215
|
+
description: `File not found: ${filePath}`
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
} catch (error) {
|
|
219
|
+
logger.error(`Error serving file: ${error.message}`);
|
|
220
|
+
reject(new AHttpServer_error.A_HttpServerError({
|
|
221
|
+
status: 500,
|
|
222
|
+
title: "Internal Server Error",
|
|
223
|
+
description: `Error serving file: ${error.message}`,
|
|
224
|
+
originalError: error
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
getCacheControl(ext) {
|
|
230
|
+
const staticAssets = [".css", ".js", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".ico", ".woff", ".woff2", ".ttf", ".otf"];
|
|
231
|
+
const dynamicContent = [".html", ".htm"];
|
|
232
|
+
if (staticAssets.includes(ext.toLowerCase())) {
|
|
233
|
+
return "public, max-age=31536000";
|
|
234
|
+
} else if (dynamicContent.includes(ext.toLowerCase())) {
|
|
235
|
+
return "public, max-age=3600";
|
|
236
|
+
} else {
|
|
237
|
+
return "public, max-age=86400";
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
__decorateClass([
|
|
242
|
+
aConcept.A_Concept.Load(),
|
|
243
|
+
__decorateParam(0, aConcept.A_Inject(aLogger.A_Logger)),
|
|
244
|
+
__decorateParam(1, aConcept.A_Inject(AServerStatic_context.A_StaticConfig)),
|
|
245
|
+
__decorateParam(2, aConcept.A_Inject(aPolyfill.A_Polyfill))
|
|
246
|
+
], A_StaticLoader.prototype, "load");
|
|
247
|
+
__decorateClass([
|
|
248
|
+
aConcept.A_Feature.Extend({
|
|
249
|
+
before: /.*/
|
|
250
|
+
}),
|
|
251
|
+
__decorateParam(0, aConcept.A_Inject(ARequest_entity.A_Request)),
|
|
252
|
+
__decorateParam(1, aConcept.A_Inject(AResponse_entity.A_Response)),
|
|
253
|
+
__decorateParam(2, aConcept.A_Inject(aLogger.A_Logger)),
|
|
254
|
+
__decorateParam(3, aConcept.A_Inject(AServerStatic_context.A_StaticConfig)),
|
|
255
|
+
__decorateParam(4, aConcept.A_Inject(aPolyfill.A_Polyfill))
|
|
256
|
+
], A_StaticLoader.prototype, _a);
|
|
257
|
+
|
|
258
|
+
exports.A_StaticLoader = A_StaticLoader;
|
|
259
|
+
//# sourceMappingURL=A-ServerStatic.component.js.map
|
|
260
|
+
//# sourceMappingURL=A-ServerStatic.component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/A-ServerStatic/A-ServerStatic.component.ts"],"names":["A_Component","A_ServerRoute","A_HttpServerError","A_Concept","A_Logger","A_StaticConfig","A_Polyfill","A_Feature","A_Request","A_Response"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,EAAA;AAUO,MAAM,uBAAuBA,oBAAA,CAAY;AAAA,EAM5C,MAAM,IAAA,CACkB,MAAA,EACM,MAAA,EACJ,QAAA,EACxB;AAEE,IAAA,IAAA,CAAK,WAAA,GAAc,MAAM,QAAA,CAAS,EAAA,EAAG;AACrC,IAAA,IAAA,CAAK,aAAA,GAAgB,MAAM,QAAA,CAAS,IAAA,EAAK;AAGzC,IAAA,MAAM,OAAA,GAAU,OAAO,iBAAA,EAAkB;AACzC,IAAA,MAAA,CAAO,IAAA;AAAA,MAAK,MAAA;AAAA,MAER,CAAA,0BAAA,CAAA;AAAA,MACA,GAAG,OAAA,CAAQ,GAAA,CAAI,CAAA,KAAA,KAAS,CAAA,EAAG,MAAM,KAAK,CAAA,IAAA,EAAO,KAAA,CAAM,SAAS,CAAA,CAAE;AAAA,KAClE;AAAA,EACJ;AAAA,EAUA,OAAO,gDAAqB,SAAS,CAAA,CACZ,KACC,GAAA,EACF,MAAA,EACM,QACJ,QAAA,EACxB;AAEE,IAAA,IAAI,GAAA,CAAI,MAAA,KAAW,KAAA,IAAS,GAAA,CAAI,WAAW,MAAA,EAAQ;AAC/C,MAAA;AAAA,IACJ;AAEA,IAAA,MAAM,EAAE,MAAA,EAAQ,GAAA,EAAI,GAAI,GA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A,MAAA,CAAA;AA0BC,eAAA,CAAA;AAAA,EAHNC,mBAAU,MAAA,CAAO;AAAA,IACd,MAAA,EAAQ;AAAA,GACX,CAAA;AAAA,EAEI,qCAASC,yBAAS,CAAA,CAAA;AAAA,EAClB,qCAASC,2BAAU,CAAA,CAAA;AAAA,EACnB,qCAASL,gBAAQ,CAAA,CAAA;AAAA,EACjB,qCAASC,oCAAc,CAAA,CAAA;AAAA,EACvB,qCAASC,oBAAU,CAAA;AAAA,CAAA,EArCf,cAAA,CAgCF,SAAA,EAAA,EAAA,CAAA","file":"A-ServerStatic.component.js","sourcesContent":["import { A_Component, A_Concept, A_Feature, A_Inject } from \"@adaas/a-concept\"\nimport { A_Request } from \"@adaas/a-server/request/A-Request.entity\";\nimport { A_Response } from \"@adaas/a-server/response/A-Response.entity\";\nimport { A_StaticConfig, A_StaticAlias } from \"./A-ServerStatic.context\";\nimport { A_HttpServerFeatures } from \"@adaas/a-server/server/A-HttpServer.constants\";\nimport { A_HttpServerError } from \"@adaas/a-server/server/A-HttpServer.error\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { A_Polyfill } from \"@adaas/a-utils/a-polyfill\";\nimport { A_ServerRoute } from \"@adaas/a-server/route/A-ServerRoute.entity\";\n\nexport class A_StaticLoader extends A_Component {\n\n private _fsPolyfill: any;\n private _pathPolyfill: any;\n\n @A_Concept.Load()\n async load(\n @A_Inject(A_Logger) logger: A_Logger,\n @A_Inject(A_StaticConfig) config: A_StaticConfig,\n @A_Inject(A_Polyfill) polyfill: A_Polyfill\n ) {\n // Initialize polyfills\n this._fsPolyfill = await polyfill.fs();\n this._pathPolyfill = await polyfill.path();\n\n // Log configured aliases\n const aliases = config.getEnabledAliases();\n logger.info('cyan',\n\n `Static aliases configured:`,\n ...aliases.map(alias => `${alias.alias} -> ${alias.directory}`)\n );\n }\n\n\n // =======================================================\n // ================ Method Definition=====================\n // =======================================================\n\n @A_Feature.Extend({\n before: /.*/\n })\n async [A_HttpServerFeatures.onRequest](\n @A_Inject(A_Request) req: A_Request,\n @A_Inject(A_Response) res: A_Response,\n @A_Inject(A_Logger) logger: A_Logger,\n @A_Inject(A_StaticConfig) config: A_StaticConfig,\n @A_Inject(A_Polyfill) polyfill: A_Polyfill\n ) {\n\n if (req.method !== 'GET' && req.method !== 'HEAD') {\n return; // Only handle GET and HEAD requests\n }\n\n const { method, url } = req;\n const route = new A_ServerRoute(url, method);\n\n // Check if this request matches any of our configured aliases\n const alias = config.findMatchingAlias(route.path);\n if (!alias) {\n return; // No static config for this path\n }\n\n try {\n // Ensure polyfills are available\n const fs = this._fsPolyfill || await polyfill.fs();\n const path = this._pathPolyfill || await polyfill.path();\n\n const staticDir = path.resolve(process.cwd(), alias.directory);\n\n // Validate static directory exists\n if (!fs.existsSync(staticDir)) {\n logger.log(\"red\", `Static directory ${staticDir} does not exist.`);\n return;\n }\n\n // Get the file path relative to the alias\n const relativePath = route.path.replace(alias.path, '');\n const safePath = this.safeFilePath(staticDir, relativePath, req.headers?.host, path, fs);\n\n await this.serveFile(safePath, res, logger, fs, path);\n\n logger.log('green', `Successfully served: ${safePath}`);\n\n } catch (error: any) {\n throw new A_HttpServerError({\n status: 500,\n title: 'Static File Serving Error',\n description: `Error serving static file for ${route.path}: ${error.message}`,\n originalError: error\n });\n }\n }\n\n /**\n * Add a custom static file alias through the config\n * @param alias - The URL path alias (e.g., '/assets')\n * @param directory - The local directory path\n * @param path - Optional custom path (defaults to alias)\n * @param config - Static config instance\n * @param logger - Logger instance for logging\n */\n public addAlias(\n alias: string,\n directory: string,\n config: A_StaticConfig,\n logger?: A_Logger,\n path?: string\n ): void {\n config.addAlias(alias, directory, path);\n\n if (logger) {\n logger.log('cyan', `Static alias added: ${alias} -> ${directory}`);\n }\n }\n\n /**\n * Remove a static file alias through the config\n * @param aliasPath - The path of the alias to remove\n * @param config - Static config instance\n * @param logger - Logger instance for logging\n */\n public removeAlias(aliasPath: string, config: A_StaticConfig, logger?: A_Logger): boolean {\n const removed = config.removeAlias(aliasPath);\n\n if (removed && logger) {\n logger.log('yellow', `Static alias removed: ${aliasPath}`);\n }\n\n return removed;\n }\n\n /**\n * Get all configured aliases from config\n * @param config - Static config instance\n */\n public getAliases(config: A_StaticConfig): A_StaticAlias[] {\n return config.getAliases();\n }\n\n /**\n * Enable or disable an alias\n * @param aliasPath - The path of the alias\n * @param enabled - Whether to enable or disable\n * @param config - Static config instance\n * @param logger - Logger instance for logging\n */\n public setAliasEnabled(\n aliasPath: string,\n enabled: boolean,\n config: A_StaticConfig,\n logger?: A_Logger\n ): boolean {\n const result = config.setAliasEnabled(aliasPath, enabled);\n\n if (result && logger) {\n logger.log('blue', `Static alias ${enabled ? 'enabled' : 'disabled'}: ${aliasPath}`);\n }\n\n return result;\n }\n\n protected getMimeType(ext: string): string {\n const mimeTypes: Record<string, string> = {\n // Text\n \".html\": \"text/html\",\n \".htm\": \"text/html\",\n \".css\": \"text/css\",\n \".txt\": \"text/plain\",\n \".md\": \"text/markdown\",\n \".xml\": \"application/xml\",\n\n // JavaScript\n \".js\": \"application/javascript\",\n \".mjs\": \"application/javascript\",\n \".jsx\": \"application/javascript\",\n \".ts\": \"application/typescript\",\n \".tsx\": \"application/typescript\",\n\n // JSON\n \".json\": \"application/json\",\n \".jsonld\": \"application/ld+json\",\n\n // Images\n \".png\": \"image/png\",\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".gif\": \"image/gif\",\n \".svg\": \"image/svg+xml\",\n \".ico\": \"image/x-icon\",\n \".webp\": \"image/webp\",\n \".bmp\": \"image/bmp\",\n \".tiff\": \"image/tiff\",\n\n // Fonts\n \".woff\": \"font/woff\",\n \".woff2\": \"font/woff2\",\n \".ttf\": \"font/ttf\",\n \".otf\": \"font/otf\",\n \".eot\": \"application/vnd.ms-fontobject\",\n\n // Audio/Video\n \".mp3\": \"audio/mpeg\",\n \".wav\": \"audio/wav\",\n \".mp4\": \"video/mp4\",\n \".webm\": \"video/webm\",\n \".ogg\": \"application/ogg\",\n\n // Archives\n \".zip\": \"application/zip\",\n \".tar\": \"application/x-tar\",\n \".gz\": \"application/gzip\",\n\n // Documents\n \".pdf\": \"application/pdf\",\n \".doc\": \"application/msword\",\n \".docx\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \".xls\": \"application/vnd.ms-excel\",\n \".xlsx\": \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n };\n\n return mimeTypes[ext.toLowerCase()] || \"application/octet-stream\";\n }\n\n\n protected safeFilePath(staticDir: string, reqUrl: string, host: string = 'localhost', pathPolyfill: any, fsPolyfill: any): string {\n const parsedUrl = new URL(reqUrl || \"/\", `http://${host}`);\n let pathname = decodeURIComponent(parsedUrl.pathname);\n\n // Prevent path traversal attacks\n pathname = pathname.replace(/\\.\\.[\\/\\\\]/g, \"\");\n\n let filePath = pathPolyfill.join(staticDir, pathname);\n\n if (!fsPolyfill.existsSync(filePath)) {\n throw new Error(`File not found: ${filePath}`);\n }\n\n return filePath;\n }\n\n protected serveFile(\n filePath: string,\n res: A_Response,\n logger: A_Logger,\n fsPolyfill: any,\n pathPolyfill: any\n ): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n try {\n if (fsPolyfill.existsSync(filePath)) {\n const ext = pathPolyfill.extname(filePath);\n const contentType = this.getMimeType(ext);\n\n // Set appropriate headers\n const headers: Record<string, string> = {\n \"Content-Type\": contentType,\n \"Cache-Control\": this.getCacheControl(ext),\n \"X-Content-Type-Options\": \"nosniff\"\n };\n\n res.writeHead(200, headers);\n\n const stream = fsPolyfill.createReadStream(filePath);\n\n if (stream && res.original) {\n stream.pipe(res.original);\n\n stream.on('end', () => {\n resolve();\n });\n\n stream.on(\"error\", (err: any) => {\n reject(new A_HttpServerError({\n status: 500,\n title: 'File Stream Error',\n description: `Error reading file stream for ${filePath}: ${err.message}`,\n originalError: err\n }));\n });\n } else {\n reject(new A_HttpServerError({\n status: 500,\n title: 'Response Stream Error',\n description: `Unable to pipe file stream for ${filePath}`,\n }));\n }\n } else {\n reject(new A_HttpServerError({\n status: 404,\n title: 'File Not Found',\n description: `File not found: ${filePath}`,\n }));\n }\n } catch (error: any) {\n logger.error(`Error serving file: ${error.message}`);\n reject(new A_HttpServerError({\n status: 500,\n title: 'Internal Server Error',\n description: `Error serving file: ${error.message}`,\n originalError: error\n }));\n }\n });\n }\n\n protected getCacheControl(ext: string): string {\n // Different cache strategies for different file types\n const staticAssets = ['.css', '.js', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.woff', '.woff2', '.ttf', '.otf'];\n const dynamicContent = ['.html', '.htm'];\n\n if (staticAssets.includes(ext.toLowerCase())) {\n return \"public, max-age=31536000\"; // 1 year for static assets\n } else if (dynamicContent.includes(ext.toLowerCase())) {\n return \"public, max-age=3600\"; // 1 hour for HTML\n } else {\n return \"public, max-age=86400\"; // 1 day for other files\n }\n }\n\n}\n\n\n"]}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { __decorateClass, __decorateParam } from '../../chunk-EQQGB2QZ.mjs';
|
|
2
|
+
import { A_Component, A_Concept, A_Inject, A_Feature } from '@adaas/a-concept';
|
|
3
|
+
import { A_Request } from '@adaas/a-server/request/A-Request.entity';
|
|
4
|
+
import { A_Response } from '@adaas/a-server/response/A-Response.entity';
|
|
5
|
+
import { A_StaticConfig } from './A-ServerStatic.context';
|
|
6
|
+
import { A_HttpServerFeatures } from '@adaas/a-server/server/A-HttpServer.constants';
|
|
7
|
+
import { A_HttpServerError } from '@adaas/a-server/server/A-HttpServer.error';
|
|
8
|
+
import { A_Logger } from '@adaas/a-utils/a-logger';
|
|
9
|
+
import { A_Polyfill } from '@adaas/a-utils/a-polyfill';
|
|
10
|
+
import { A_ServerRoute } from '@adaas/a-server/route/A-ServerRoute.entity';
|
|
11
|
+
|
|
12
|
+
var _a;
|
|
13
|
+
class A_StaticLoader extends A_Component {
|
|
14
|
+
async load(logger, config, polyfill) {
|
|
15
|
+
this._fsPolyfill = await polyfill.fs();
|
|
16
|
+
this._pathPolyfill = await polyfill.path();
|
|
17
|
+
const aliases = config.getEnabledAliases();
|
|
18
|
+
logger.info(
|
|
19
|
+
"cyan",
|
|
20
|
+
`Static aliases configured:`,
|
|
21
|
+
...aliases.map((alias) => `${alias.alias} -> ${alias.directory}`)
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
async [_a = A_HttpServerFeatures.onRequest](req, res, logger, config, polyfill) {
|
|
25
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const { method, url } = req;
|
|
29
|
+
const route = new A_ServerRoute(url, method);
|
|
30
|
+
const alias = config.findMatchingAlias(route.path);
|
|
31
|
+
if (!alias) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const fs = this._fsPolyfill || await polyfill.fs();
|
|
36
|
+
const path = this._pathPolyfill || await polyfill.path();
|
|
37
|
+
const staticDir = path.resolve(process.cwd(), alias.directory);
|
|
38
|
+
if (!fs.existsSync(staticDir)) {
|
|
39
|
+
logger.log("red", `Static directory ${staticDir} does not exist.`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const relativePath = route.path.replace(alias.path, "");
|
|
43
|
+
const safePath = this.safeFilePath(staticDir, relativePath, req.headers?.host, path, fs);
|
|
44
|
+
await this.serveFile(safePath, res, logger, fs, path);
|
|
45
|
+
logger.log("green", `Successfully served: ${safePath}`);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new A_HttpServerError({
|
|
48
|
+
status: 500,
|
|
49
|
+
title: "Static File Serving Error",
|
|
50
|
+
description: `Error serving static file for ${route.path}: ${error.message}`,
|
|
51
|
+
originalError: error
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Add a custom static file alias through the config
|
|
57
|
+
* @param alias - The URL path alias (e.g., '/assets')
|
|
58
|
+
* @param directory - The local directory path
|
|
59
|
+
* @param path - Optional custom path (defaults to alias)
|
|
60
|
+
* @param config - Static config instance
|
|
61
|
+
* @param logger - Logger instance for logging
|
|
62
|
+
*/
|
|
63
|
+
addAlias(alias, directory, config, logger, path) {
|
|
64
|
+
config.addAlias(alias, directory, path);
|
|
65
|
+
if (logger) {
|
|
66
|
+
logger.log("cyan", `Static alias added: ${alias} -> ${directory}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Remove a static file alias through the config
|
|
71
|
+
* @param aliasPath - The path of the alias to remove
|
|
72
|
+
* @param config - Static config instance
|
|
73
|
+
* @param logger - Logger instance for logging
|
|
74
|
+
*/
|
|
75
|
+
removeAlias(aliasPath, config, logger) {
|
|
76
|
+
const removed = config.removeAlias(aliasPath);
|
|
77
|
+
if (removed && logger) {
|
|
78
|
+
logger.log("yellow", `Static alias removed: ${aliasPath}`);
|
|
79
|
+
}
|
|
80
|
+
return removed;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get all configured aliases from config
|
|
84
|
+
* @param config - Static config instance
|
|
85
|
+
*/
|
|
86
|
+
getAliases(config) {
|
|
87
|
+
return config.getAliases();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Enable or disable an alias
|
|
91
|
+
* @param aliasPath - The path of the alias
|
|
92
|
+
* @param enabled - Whether to enable or disable
|
|
93
|
+
* @param config - Static config instance
|
|
94
|
+
* @param logger - Logger instance for logging
|
|
95
|
+
*/
|
|
96
|
+
setAliasEnabled(aliasPath, enabled, config, logger) {
|
|
97
|
+
const result = config.setAliasEnabled(aliasPath, enabled);
|
|
98
|
+
if (result && logger) {
|
|
99
|
+
logger.log("blue", `Static alias ${enabled ? "enabled" : "disabled"}: ${aliasPath}`);
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
getMimeType(ext) {
|
|
104
|
+
const mimeTypes = {
|
|
105
|
+
// Text
|
|
106
|
+
".html": "text/html",
|
|
107
|
+
".htm": "text/html",
|
|
108
|
+
".css": "text/css",
|
|
109
|
+
".txt": "text/plain",
|
|
110
|
+
".md": "text/markdown",
|
|
111
|
+
".xml": "application/xml",
|
|
112
|
+
// JavaScript
|
|
113
|
+
".js": "application/javascript",
|
|
114
|
+
".mjs": "application/javascript",
|
|
115
|
+
".jsx": "application/javascript",
|
|
116
|
+
".ts": "application/typescript",
|
|
117
|
+
".tsx": "application/typescript",
|
|
118
|
+
// JSON
|
|
119
|
+
".json": "application/json",
|
|
120
|
+
".jsonld": "application/ld+json",
|
|
121
|
+
// Images
|
|
122
|
+
".png": "image/png",
|
|
123
|
+
".jpg": "image/jpeg",
|
|
124
|
+
".jpeg": "image/jpeg",
|
|
125
|
+
".gif": "image/gif",
|
|
126
|
+
".svg": "image/svg+xml",
|
|
127
|
+
".ico": "image/x-icon",
|
|
128
|
+
".webp": "image/webp",
|
|
129
|
+
".bmp": "image/bmp",
|
|
130
|
+
".tiff": "image/tiff",
|
|
131
|
+
// Fonts
|
|
132
|
+
".woff": "font/woff",
|
|
133
|
+
".woff2": "font/woff2",
|
|
134
|
+
".ttf": "font/ttf",
|
|
135
|
+
".otf": "font/otf",
|
|
136
|
+
".eot": "application/vnd.ms-fontobject",
|
|
137
|
+
// Audio/Video
|
|
138
|
+
".mp3": "audio/mpeg",
|
|
139
|
+
".wav": "audio/wav",
|
|
140
|
+
".mp4": "video/mp4",
|
|
141
|
+
".webm": "video/webm",
|
|
142
|
+
".ogg": "application/ogg",
|
|
143
|
+
// Archives
|
|
144
|
+
".zip": "application/zip",
|
|
145
|
+
".tar": "application/x-tar",
|
|
146
|
+
".gz": "application/gzip",
|
|
147
|
+
// Documents
|
|
148
|
+
".pdf": "application/pdf",
|
|
149
|
+
".doc": "application/msword",
|
|
150
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
151
|
+
".xls": "application/vnd.ms-excel",
|
|
152
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
153
|
+
};
|
|
154
|
+
return mimeTypes[ext.toLowerCase()] || "application/octet-stream";
|
|
155
|
+
}
|
|
156
|
+
safeFilePath(staticDir, reqUrl, host = "localhost", pathPolyfill, fsPolyfill) {
|
|
157
|
+
const parsedUrl = new URL(reqUrl || "/", `http://${host}`);
|
|
158
|
+
let pathname = decodeURIComponent(parsedUrl.pathname);
|
|
159
|
+
pathname = pathname.replace(/\.\.[\/\\]/g, "");
|
|
160
|
+
let filePath = pathPolyfill.join(staticDir, pathname);
|
|
161
|
+
if (!fsPolyfill.existsSync(filePath)) {
|
|
162
|
+
throw new Error(`File not found: ${filePath}`);
|
|
163
|
+
}
|
|
164
|
+
return filePath;
|
|
165
|
+
}
|
|
166
|
+
serveFile(filePath, res, logger, fsPolyfill, pathPolyfill) {
|
|
167
|
+
return new Promise((resolve, reject) => {
|
|
168
|
+
try {
|
|
169
|
+
if (fsPolyfill.existsSync(filePath)) {
|
|
170
|
+
const ext = pathPolyfill.extname(filePath);
|
|
171
|
+
const contentType = this.getMimeType(ext);
|
|
172
|
+
const headers = {
|
|
173
|
+
"Content-Type": contentType,
|
|
174
|
+
"Cache-Control": this.getCacheControl(ext),
|
|
175
|
+
"X-Content-Type-Options": "nosniff"
|
|
176
|
+
};
|
|
177
|
+
res.writeHead(200, headers);
|
|
178
|
+
const stream = fsPolyfill.createReadStream(filePath);
|
|
179
|
+
if (stream && res.original) {
|
|
180
|
+
stream.pipe(res.original);
|
|
181
|
+
stream.on("end", () => {
|
|
182
|
+
resolve();
|
|
183
|
+
});
|
|
184
|
+
stream.on("error", (err) => {
|
|
185
|
+
reject(new A_HttpServerError({
|
|
186
|
+
status: 500,
|
|
187
|
+
title: "File Stream Error",
|
|
188
|
+
description: `Error reading file stream for ${filePath}: ${err.message}`,
|
|
189
|
+
originalError: err
|
|
190
|
+
}));
|
|
191
|
+
});
|
|
192
|
+
} else {
|
|
193
|
+
reject(new A_HttpServerError({
|
|
194
|
+
status: 500,
|
|
195
|
+
title: "Response Stream Error",
|
|
196
|
+
description: `Unable to pipe file stream for ${filePath}`
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
reject(new A_HttpServerError({
|
|
201
|
+
status: 404,
|
|
202
|
+
title: "File Not Found",
|
|
203
|
+
description: `File not found: ${filePath}`
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
} catch (error) {
|
|
207
|
+
logger.error(`Error serving file: ${error.message}`);
|
|
208
|
+
reject(new A_HttpServerError({
|
|
209
|
+
status: 500,
|
|
210
|
+
title: "Internal Server Error",
|
|
211
|
+
description: `Error serving file: ${error.message}`,
|
|
212
|
+
originalError: error
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
getCacheControl(ext) {
|
|
218
|
+
const staticAssets = [".css", ".js", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".ico", ".woff", ".woff2", ".ttf", ".otf"];
|
|
219
|
+
const dynamicContent = [".html", ".htm"];
|
|
220
|
+
if (staticAssets.includes(ext.toLowerCase())) {
|
|
221
|
+
return "public, max-age=31536000";
|
|
222
|
+
} else if (dynamicContent.includes(ext.toLowerCase())) {
|
|
223
|
+
return "public, max-age=3600";
|
|
224
|
+
} else {
|
|
225
|
+
return "public, max-age=86400";
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
__decorateClass([
|
|
230
|
+
A_Concept.Load(),
|
|
231
|
+
__decorateParam(0, A_Inject(A_Logger)),
|
|
232
|
+
__decorateParam(1, A_Inject(A_StaticConfig)),
|
|
233
|
+
__decorateParam(2, A_Inject(A_Polyfill))
|
|
234
|
+
], A_StaticLoader.prototype, "load", 1);
|
|
235
|
+
__decorateClass([
|
|
236
|
+
A_Feature.Extend({
|
|
237
|
+
before: /.*/
|
|
238
|
+
}),
|
|
239
|
+
__decorateParam(0, A_Inject(A_Request)),
|
|
240
|
+
__decorateParam(1, A_Inject(A_Response)),
|
|
241
|
+
__decorateParam(2, A_Inject(A_Logger)),
|
|
242
|
+
__decorateParam(3, A_Inject(A_StaticConfig)),
|
|
243
|
+
__decorateParam(4, A_Inject(A_Polyfill))
|
|
244
|
+
], A_StaticLoader.prototype, _a, 1);
|
|
245
|
+
|
|
246
|
+
export { A_StaticLoader };
|
|
247
|
+
//# sourceMappingURL=A-ServerStatic.component.mjs.map
|
|
248
|
+
//# sourceMappingURL=A-ServerStatic.component.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/A-ServerStatic/A-ServerStatic.component.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,IAAA,EAAA;AAUO,MAAM,uBAAuB,WAAA,CAAY;AAAA,EAM5C,MAAM,IAAA,CACkB,MAAA,EACM,MAAA,EACJ,QAAA,EACxB;AAEE,IAAA,IAAA,CAAK,WAAA,GAAc,MAAM,QAAA,CAAS,EAAA,EAAG;AACrC,IAAA,IAAA,CAAK,aAAA,GAAgB,MAAM,QAAA,CAAS,IAAA,EAAK;AAGzC,IAAA,MAAM,OAAA,GAAU,OAAO,iBAAA,EAAkB;AACzC,IAAA,MAAA,CAAO,IAAA;AAAA,MAAK,MAAA;AAAA,MAER,CAAA,0BAAA,CAAA;AAAA,MACA,GAAG,OAAA,CAAQ,GAAA,CAAI,CAAA,KAAA,KAAS,CAAA,EAAG,MAAM,KAAK,CAAA,IAAA,EAAO,KAAA,CAAM,SAAS,CAAA,CAAE;AAAA,KAClE;AAAA,EACJ;AAAA,EAUA,OAAO,0BAAqB,SAAS,CAAA,CACZ,KACC,GAAA,EACF,MAAA,EACM,QACJ,QAAA,EACxB;AAEE,IAAA,IAAI,GAAA,CAAI,MAAA,KAAW,KAAA,IAAS,GAAA,CAAI,WAAW,MAAA,EAAQ;AAC/C,MAAA;AAAA,IACJ;AAEA,IAAA,MAAM,EAAE,MAAA,EAAQ,GAAA,EAAI,GAAI,GAAA;AACxB,IAAA,MAAM,KAAA,GAA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AAAA,EAHN,UAAU,MAAA,CAAO;AAAA,IACd,MAAA,EAAQ;AAAA,GACX,CAAA;AAAA,EAEI,4BAAS,SAAS,CAAA,CAAA;AAAA,EAClB,4BAAS,UAAU,CAAA,CAAA;AAAA,EACnB,4BAAS,QAAQ,CAAA,CAAA;AAAA,EACjB,4BAAS,cAAc,CAAA,CAAA;AAAA,EACvB,4BAAS,UAAU,CAAA;AAAA,CAAA,EArCf,cAAA,CAgCF,SAAA,EAAA,EAAA,EAAA,CAAA,CAAA","file":"A-ServerStatic.component.mjs","sourcesContent":["import { A_Component, A_Concept, A_Feature, A_Inject } from \"@adaas/a-concept\"\nimport { A_Request } from \"@adaas/a-server/request/A-Request.entity\";\nimport { A_Response } from \"@adaas/a-server/response/A-Response.entity\";\nimport { A_StaticConfig, A_StaticAlias } from \"./A-ServerStatic.context\";\nimport { A_HttpServerFeatures } from \"@adaas/a-server/server/A-HttpServer.constants\";\nimport { A_HttpServerError } from \"@adaas/a-server/server/A-HttpServer.error\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { A_Polyfill } from \"@adaas/a-utils/a-polyfill\";\nimport { A_ServerRoute } from \"@adaas/a-server/route/A-ServerRoute.entity\";\n\nexport class A_StaticLoader extends A_Component {\n\n private _fsPolyfill: any;\n private _pathPolyfill: any;\n\n @A_Concept.Load()\n async load(\n @A_Inject(A_Logger) logger: A_Logger,\n @A_Inject(A_StaticConfig) config: A_StaticConfig,\n @A_Inject(A_Polyfill) polyfill: A_Polyfill\n ) {\n // Initialize polyfills\n this._fsPolyfill = await polyfill.fs();\n this._pathPolyfill = await polyfill.path();\n\n // Log configured aliases\n const aliases = config.getEnabledAliases();\n logger.info('cyan',\n\n `Static aliases configured:`,\n ...aliases.map(alias => `${alias.alias} -> ${alias.directory}`)\n );\n }\n\n\n // =======================================================\n // ================ Method Definition=====================\n // =======================================================\n\n @A_Feature.Extend({\n before: /.*/\n })\n async [A_HttpServerFeatures.onRequest](\n @A_Inject(A_Request) req: A_Request,\n @A_Inject(A_Response) res: A_Response,\n @A_Inject(A_Logger) logger: A_Logger,\n @A_Inject(A_StaticConfig) config: A_StaticConfig,\n @A_Inject(A_Polyfill) polyfill: A_Polyfill\n ) {\n\n if (req.method !== 'GET' && req.method !== 'HEAD') {\n return; // Only handle GET and HEAD requests\n }\n\n const { method, url } = req;\n const route = new A_ServerRoute(url, method);\n\n // Check if this request matches any of our configured aliases\n const alias = config.findMatchingAlias(route.path);\n if (!alias) {\n return; // No static config for this path\n }\n\n try {\n // Ensure polyfills are available\n const fs = this._fsPolyfill || await polyfill.fs();\n const path = this._pathPolyfill || await polyfill.path();\n\n const staticDir = path.resolve(process.cwd(), alias.directory);\n\n // Validate static directory exists\n if (!fs.existsSync(staticDir)) {\n logger.log(\"red\", `Static directory ${staticDir} does not exist.`);\n return;\n }\n\n // Get the file path relative to the alias\n const relativePath = route.path.replace(alias.path, '');\n const safePath = this.safeFilePath(staticDir, relativePath, req.headers?.host, path, fs);\n\n await this.serveFile(safePath, res, logger, fs, path);\n\n logger.log('green', `Successfully served: ${safePath}`);\n\n } catch (error: any) {\n throw new A_HttpServerError({\n status: 500,\n title: 'Static File Serving Error',\n description: `Error serving static file for ${route.path}: ${error.message}`,\n originalError: error\n });\n }\n }\n\n /**\n * Add a custom static file alias through the config\n * @param alias - The URL path alias (e.g., '/assets')\n * @param directory - The local directory path\n * @param path - Optional custom path (defaults to alias)\n * @param config - Static config instance\n * @param logger - Logger instance for logging\n */\n public addAlias(\n alias: string,\n directory: string,\n config: A_StaticConfig,\n logger?: A_Logger,\n path?: string\n ): void {\n config.addAlias(alias, directory, path);\n\n if (logger) {\n logger.log('cyan', `Static alias added: ${alias} -> ${directory}`);\n }\n }\n\n /**\n * Remove a static file alias through the config\n * @param aliasPath - The path of the alias to remove\n * @param config - Static config instance\n * @param logger - Logger instance for logging\n */\n public removeAlias(aliasPath: string, config: A_StaticConfig, logger?: A_Logger): boolean {\n const removed = config.removeAlias(aliasPath);\n\n if (removed && logger) {\n logger.log('yellow', `Static alias removed: ${aliasPath}`);\n }\n\n return removed;\n }\n\n /**\n * Get all configured aliases from config\n * @param config - Static config instance\n */\n public getAliases(config: A_StaticConfig): A_StaticAlias[] {\n return config.getAliases();\n }\n\n /**\n * Enable or disable an alias\n * @param aliasPath - The path of the alias\n * @param enabled - Whether to enable or disable\n * @param config - Static config instance\n * @param logger - Logger instance for logging\n */\n public setAliasEnabled(\n aliasPath: string,\n enabled: boolean,\n config: A_StaticConfig,\n logger?: A_Logger\n ): boolean {\n const result = config.setAliasEnabled(aliasPath, enabled);\n\n if (result && logger) {\n logger.log('blue', `Static alias ${enabled ? 'enabled' : 'disabled'}: ${aliasPath}`);\n }\n\n return result;\n }\n\n protected getMimeType(ext: string): string {\n const mimeTypes: Record<string, string> = {\n // Text\n \".html\": \"text/html\",\n \".htm\": \"text/html\",\n \".css\": \"text/css\",\n \".txt\": \"text/plain\",\n \".md\": \"text/markdown\",\n \".xml\": \"application/xml\",\n\n // JavaScript\n \".js\": \"application/javascript\",\n \".mjs\": \"application/javascript\",\n \".jsx\": \"application/javascript\",\n \".ts\": \"application/typescript\",\n \".tsx\": \"application/typescript\",\n\n // JSON\n \".json\": \"application/json\",\n \".jsonld\": \"application/ld+json\",\n\n // Images\n \".png\": \"image/png\",\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".gif\": \"image/gif\",\n \".svg\": \"image/svg+xml\",\n \".ico\": \"image/x-icon\",\n \".webp\": \"image/webp\",\n \".bmp\": \"image/bmp\",\n \".tiff\": \"image/tiff\",\n\n // Fonts\n \".woff\": \"font/woff\",\n \".woff2\": \"font/woff2\",\n \".ttf\": \"font/ttf\",\n \".otf\": \"font/otf\",\n \".eot\": \"application/vnd.ms-fontobject\",\n\n // Audio/Video\n \".mp3\": \"audio/mpeg\",\n \".wav\": \"audio/wav\",\n \".mp4\": \"video/mp4\",\n \".webm\": \"video/webm\",\n \".ogg\": \"application/ogg\",\n\n // Archives\n \".zip\": \"application/zip\",\n \".tar\": \"application/x-tar\",\n \".gz\": \"application/gzip\",\n\n // Documents\n \".pdf\": \"application/pdf\",\n \".doc\": \"application/msword\",\n \".docx\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \".xls\": \"application/vnd.ms-excel\",\n \".xlsx\": \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n };\n\n return mimeTypes[ext.toLowerCase()] || \"application/octet-stream\";\n }\n\n\n protected safeFilePath(staticDir: string, reqUrl: string, host: string = 'localhost', pathPolyfill: any, fsPolyfill: any): string {\n const parsedUrl = new URL(reqUrl || \"/\", `http://${host}`);\n let pathname = decodeURIComponent(parsedUrl.pathname);\n\n // Prevent path traversal attacks\n pathname = pathname.replace(/\\.\\.[\\/\\\\]/g, \"\");\n\n let filePath = pathPolyfill.join(staticDir, pathname);\n\n if (!fsPolyfill.existsSync(filePath)) {\n throw new Error(`File not found: ${filePath}`);\n }\n\n return filePath;\n }\n\n protected serveFile(\n filePath: string,\n res: A_Response,\n logger: A_Logger,\n fsPolyfill: any,\n pathPolyfill: any\n ): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n try {\n if (fsPolyfill.existsSync(filePath)) {\n const ext = pathPolyfill.extname(filePath);\n const contentType = this.getMimeType(ext);\n\n // Set appropriate headers\n const headers: Record<string, string> = {\n \"Content-Type\": contentType,\n \"Cache-Control\": this.getCacheControl(ext),\n \"X-Content-Type-Options\": \"nosniff\"\n };\n\n res.writeHead(200, headers);\n\n const stream = fsPolyfill.createReadStream(filePath);\n\n if (stream && res.original) {\n stream.pipe(res.original);\n\n stream.on('end', () => {\n resolve();\n });\n\n stream.on(\"error\", (err: any) => {\n reject(new A_HttpServerError({\n status: 500,\n title: 'File Stream Error',\n description: `Error reading file stream for ${filePath}: ${err.message}`,\n originalError: err\n }));\n });\n } else {\n reject(new A_HttpServerError({\n status: 500,\n title: 'Response Stream Error',\n description: `Unable to pipe file stream for ${filePath}`,\n }));\n }\n } else {\n reject(new A_HttpServerError({\n status: 404,\n title: 'File Not Found',\n description: `File not found: ${filePath}`,\n }));\n }\n } catch (error: any) {\n logger.error(`Error serving file: ${error.message}`);\n reject(new A_HttpServerError({\n status: 500,\n title: 'Internal Server Error',\n description: `Error serving file: ${error.message}`,\n originalError: error\n }));\n }\n });\n }\n\n protected getCacheControl(ext: string): string {\n // Different cache strategies for different file types\n const staticAssets = ['.css', '.js', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.woff', '.woff2', '.ttf', '.otf'];\n const dynamicContent = ['.html', '.htm'];\n\n if (staticAssets.includes(ext.toLowerCase())) {\n return \"public, max-age=31536000\"; // 1 year for static assets\n } else if (dynamicContent.includes(ext.toLowerCase())) {\n return \"public, max-age=3600\"; // 1 hour for HTML\n } else {\n return \"public, max-age=86400\"; // 1 day for other files\n }\n }\n\n}\n\n\n"]}
|