jopijs 0.0.1
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/README.md +134 -0
- package/bin/jopib.js +4 -0
- package/bin/jopin.js +4 -0
- package/dist/@bundler/_logs.d.ts +2 -0
- package/dist/@bundler/_logs.js +4 -0
- package/dist/@bundler/_logs.js.map +1 -0
- package/dist/@bundler/core.d.ts +1 -0
- package/dist/@bundler/core.js +34 -0
- package/dist/@bundler/core.js.map +1 -0
- package/dist/@bundler/esbuild.d.ts +6 -0
- package/dist/@bundler/esbuild.js +111 -0
- package/dist/@bundler/esbuild.js.map +1 -0
- package/dist/@bundler/index.d.ts +2 -0
- package/dist/@bundler/index.js +3 -0
- package/dist/@bundler/index.js.map +1 -0
- package/dist/@bundler/plugins.d.ts +13 -0
- package/dist/@bundler/plugins.js +145 -0
- package/dist/@bundler/plugins.js.map +1 -0
- package/dist/@bundler/tailwind.d.ts +3 -0
- package/dist/@bundler/tailwind.js +119 -0
- package/dist/@bundler/tailwind.js.map +1 -0
- package/dist/@core/PageComponent.d.ts +6 -0
- package/dist/@core/PageComponent.js +10 -0
- package/dist/@core/PageComponent.js.map +1 -0
- package/dist/@core/_logs.d.ts +7 -0
- package/dist/@core/_logs.js +9 -0
- package/dist/@core/_logs.js.map +1 -0
- package/dist/@core/automaticStartStop.d.ts +25 -0
- package/dist/@core/automaticStartStop.js +106 -0
- package/dist/@core/automaticStartStop.js.map +1 -0
- package/dist/@core/browserCacheControl.d.ts +21 -0
- package/dist/@core/browserCacheControl.js +17 -0
- package/dist/@core/browserCacheControl.js.map +1 -0
- package/dist/@core/bundler/bundler.d.ts +22 -0
- package/dist/@core/bundler/bundler.js +90 -0
- package/dist/@core/bundler/bundler.js.map +1 -0
- package/dist/@core/bundler/common.d.ts +2 -0
- package/dist/@core/bundler/common.js +17 -0
- package/dist/@core/bundler/common.js.map +1 -0
- package/dist/@core/bundler/config.d.ts +20 -0
- package/dist/@core/bundler/config.js +11 -0
- package/dist/@core/bundler/config.js.map +1 -0
- package/dist/@core/bundler/extraContent.d.ts +6 -0
- package/dist/@core/bundler/extraContent.js +27 -0
- package/dist/@core/bundler/extraContent.js.map +1 -0
- package/dist/@core/bundler/pagesGenerator.d.ts +1 -0
- package/dist/@core/bundler/pagesGenerator.js +173 -0
- package/dist/@core/bundler/pagesGenerator.js.map +1 -0
- package/dist/@core/bundler/server.d.ts +8 -0
- package/dist/@core/bundler/server.js +35 -0
- package/dist/@core/bundler/server.js.map +1 -0
- package/dist/@core/caches/InMemoryCache.d.ts +35 -0
- package/dist/@core/caches/InMemoryCache.js +353 -0
- package/dist/@core/caches/InMemoryCache.js.map +1 -0
- package/dist/@core/caches/SimpleFileCache.d.ts +18 -0
- package/dist/@core/caches/SimpleFileCache.js +171 -0
- package/dist/@core/caches/SimpleFileCache.js.map +1 -0
- package/dist/@core/caches/cache.d.ts +36 -0
- package/dist/@core/caches/cache.js +33 -0
- package/dist/@core/caches/cache.js.map +1 -0
- package/dist/@core/caches/webSiteMirrorCache.d.ts +16 -0
- package/dist/@core/caches/webSiteMirrorCache.js +81 -0
- package/dist/@core/caches/webSiteMirrorCache.js.map +1 -0
- package/dist/@core/gzip.d.ts +4 -0
- package/dist/@core/gzip.js +31 -0
- package/dist/@core/gzip.js.map +1 -0
- package/dist/@core/index.d.ts +18 -0
- package/dist/@core/index.js +19 -0
- package/dist/@core/index.js.map +1 -0
- package/dist/@core/internalTools.d.ts +14 -0
- package/dist/@core/internalTools.js +79 -0
- package/dist/@core/internalTools.js.map +1 -0
- package/dist/@core/jQuery.d.ts +5 -0
- package/dist/@core/jQuery.js +18 -0
- package/dist/@core/jQuery.js.map +1 -0
- package/dist/@core/jopiEasy.d.ts +287 -0
- package/dist/@core/jopiEasy.js +983 -0
- package/dist/@core/jopiEasy.js.map +1 -0
- package/dist/@core/jopiRequest.d.ts +269 -0
- package/dist/@core/jopiRequest.js +1060 -0
- package/dist/@core/jopiRequest.js.map +1 -0
- package/dist/@core/jopiServer.d.ts +77 -0
- package/dist/@core/jopiServer.js +100 -0
- package/dist/@core/jopiServer.js.map +1 -0
- package/dist/@core/jopiWebSite.d.ts +319 -0
- package/dist/@core/jopiWebSite.js +653 -0
- package/dist/@core/jopiWebSite.js.map +1 -0
- package/dist/@core/letsEncrypt.d.ts +25 -0
- package/dist/@core/letsEncrypt.js +189 -0
- package/dist/@core/letsEncrypt.js.map +1 -0
- package/dist/@core/linker.d.ts +4 -0
- package/dist/@core/linker.js +37 -0
- package/dist/@core/linker.js.map +1 -0
- package/dist/@core/loadBalancing.d.ts +18 -0
- package/dist/@core/loadBalancing.js +126 -0
- package/dist/@core/loadBalancing.js.map +1 -0
- package/dist/@core/middlewares/CorsMiddleware.d.ts +5 -0
- package/dist/@core/middlewares/CorsMiddleware.js +15 -0
- package/dist/@core/middlewares/CorsMiddleware.js.map +1 -0
- package/dist/@core/middlewares/DdosProtection.d.ts +42 -0
- package/dist/@core/middlewares/DdosProtection.js +62 -0
- package/dist/@core/middlewares/DdosProtection.js.map +1 -0
- package/dist/@core/middlewares/index.d.ts +10 -0
- package/dist/@core/middlewares/index.js +14 -0
- package/dist/@core/middlewares/index.js.map +1 -0
- package/dist/@core/publicTools.d.ts +8 -0
- package/dist/@core/publicTools.js +11 -0
- package/dist/@core/publicTools.js.map +1 -0
- package/dist/@core/routeConfig.d.ts +48 -0
- package/dist/@core/routeConfig.js +102 -0
- package/dist/@core/routeConfig.js.map +1 -0
- package/dist/@core/searchParamFilter.d.ts +70 -0
- package/dist/@core/searchParamFilter.js +212 -0
- package/dist/@core/searchParamFilter.js.map +1 -0
- package/dist/@core/serverFetch.d.ts +122 -0
- package/dist/@core/serverFetch.js +312 -0
- package/dist/@core/serverFetch.js.map +1 -0
- package/dist/@core/serverImpl/server_bunjs.d.ts +29 -0
- package/dist/@core/serverImpl/server_bunjs.js +180 -0
- package/dist/@core/serverImpl/server_bunjs.js.map +1 -0
- package/dist/@core/serverImpl/server_nodejs.d.ts +22 -0
- package/dist/@core/serverImpl/server_nodejs.js +235 -0
- package/dist/@core/serverImpl/server_nodejs.js.map +1 -0
- package/dist/@core/serverInstanceBuilder.d.ts +17 -0
- package/dist/@core/serverInstanceBuilder.js +14 -0
- package/dist/@core/serverInstanceBuilder.js.map +1 -0
- package/dist/@core/userStores.d.ts +13 -0
- package/dist/@core/userStores.js +20 -0
- package/dist/@core/userStores.js.map +1 -0
- package/dist/@crawler/common.d.ts +203 -0
- package/dist/@crawler/common.js +68 -0
- package/dist/@crawler/common.js.map +1 -0
- package/dist/@crawler/core.d.ts +87 -0
- package/dist/@crawler/core.js +586 -0
- package/dist/@crawler/core.js.map +1 -0
- package/dist/@crawler/directFileCache.d.ts +10 -0
- package/dist/@crawler/directFileCache.js +60 -0
- package/dist/@crawler/directFileCache.js.map +1 -0
- package/dist/@crawler/index.d.ts +4 -0
- package/dist/@crawler/index.js +5 -0
- package/dist/@crawler/index.js.map +1 -0
- package/dist/@crawler/urlMapping.d.ts +21 -0
- package/dist/@crawler/urlMapping.js +52 -0
- package/dist/@crawler/urlMapping.js.map +1 -0
- package/dist/@crawler/utils.d.ts +6 -0
- package/dist/@crawler/utils.js +13 -0
- package/dist/@crawler/utils.js.map +1 -0
- package/dist/@generated/index.d.ts +29 -0
- package/dist/@generated/index.js +93 -0
- package/dist/@generated/index.js.map +1 -0
- package/dist/@linker/arobaseTypes.d.ts +50 -0
- package/dist/@linker/arobaseTypes.js +235 -0
- package/dist/@linker/arobaseTypes.js.map +1 -0
- package/dist/@linker/changeProof.d.ts +5 -0
- package/dist/@linker/changeProof.js +50 -0
- package/dist/@linker/changeProof.js.map +1 -0
- package/dist/@linker/config.d.ts +2 -0
- package/dist/@linker/config.js +40 -0
- package/dist/@linker/config.js.map +1 -0
- package/dist/@linker/engine.d.ts +156 -0
- package/dist/@linker/engine.js +665 -0
- package/dist/@linker/engine.js.map +1 -0
- package/dist/@linker/index.d.ts +3 -0
- package/dist/@linker/index.js +4 -0
- package/dist/@linker/index.js.map +1 -0
- package/dist/@linker/install.d.ts +4 -0
- package/dist/@linker/install.js +42 -0
- package/dist/@linker/install.js.map +1 -0
- package/dist/@linker/modInstaller.d.ts +10 -0
- package/dist/@linker/modInstaller.js +38 -0
- package/dist/@linker/modInstaller.js.map +1 -0
- package/dist/@linker/typeEvents.d.ts +9 -0
- package/dist/@linker/typeEvents.js +48 -0
- package/dist/@linker/typeEvents.js.map +1 -0
- package/dist/@linker/typeRoutes.d.ts +23 -0
- package/dist/@linker/typeRoutes.js +197 -0
- package/dist/@linker/typeRoutes.js.map +1 -0
- package/dist/@linker/typeUiComposite.d.ts +6 -0
- package/dist/@linker/typeUiComposite.js +16 -0
- package/dist/@linker/typeUiComposite.js.map +1 -0
- package/dist/@loader/index.d.ts +1 -0
- package/dist/@loader/index.js +17 -0
- package/dist/@loader/index.js.map +1 -0
- package/dist/@loader/nodeJsLoader.d.ts +2 -0
- package/dist/@loader/nodeJsLoader.js +19 -0
- package/dist/@loader/nodeJsLoader.js.map +1 -0
- package/dist/@loader-client/index.d.ts +33 -0
- package/dist/@loader-client/index.js +98 -0
- package/dist/@loader-client/index.js.map +1 -0
- package/dist/@loader-tools/bunJsLoader.d.ts +1 -0
- package/dist/@loader-tools/bunJsLoader.js +28 -0
- package/dist/@loader-tools/bunJsLoader.js.map +1 -0
- package/dist/@loader-tools/config.d.ts +49 -0
- package/dist/@loader-tools/config.js +79 -0
- package/dist/@loader-tools/config.js.map +1 -0
- package/dist/@loader-tools/cssModuleCompiler.d.ts +5 -0
- package/dist/@loader-tools/cssModuleCompiler.js +65 -0
- package/dist/@loader-tools/cssModuleCompiler.js.map +1 -0
- package/dist/@loader-tools/esBuildPlugin.d.ts +5 -0
- package/dist/@loader-tools/esBuildPlugin.js +113 -0
- package/dist/@loader-tools/esBuildPlugin.js.map +1 -0
- package/dist/@loader-tools/index.d.ts +9 -0
- package/dist/@loader-tools/index.js +10 -0
- package/dist/@loader-tools/index.js.map +1 -0
- package/dist/@loader-tools/jopin.d.ts +10 -0
- package/dist/@loader-tools/jopin.js +331 -0
- package/dist/@loader-tools/jopin.js.map +1 -0
- package/dist/@loader-tools/nodeJsLoader.d.ts +13 -0
- package/dist/@loader-tools/nodeJsLoader.js +101 -0
- package/dist/@loader-tools/nodeJsLoader.js.map +1 -0
- package/dist/@loader-tools/nodeJsResolver.d.ts +2 -0
- package/dist/@loader-tools/nodeJsResolver.js +117 -0
- package/dist/@loader-tools/nodeJsResolver.js.map +1 -0
- package/dist/@loader-tools/rules.d.ts +3 -0
- package/dist/@loader-tools/rules.js +33 -0
- package/dist/@loader-tools/rules.js.map +1 -0
- package/dist/@loader-tools/sourceChangesWatcher.d.ts +39 -0
- package/dist/@loader-tools/sourceChangesWatcher.js +182 -0
- package/dist/@loader-tools/sourceChangesWatcher.js.map +1 -0
- package/dist/@loader-tools/tools.d.ts +21 -0
- package/dist/@loader-tools/tools.js +113 -0
- package/dist/@loader-tools/tools.js.map +1 -0
- package/dist/@loader-tools/transform.d.ts +5 -0
- package/dist/@loader-tools/transform.js +114 -0
- package/dist/@loader-tools/transform.js.map +1 -0
- package/dist/@loader-tools/virtualUrl.d.ts +9 -0
- package/dist/@loader-tools/virtualUrl.js +40 -0
- package/dist/@loader-tools/virtualUrl.js.map +1 -0
- package/dist/@tool-jopinb/index.d.ts +1 -0
- package/dist/@tool-jopinb/index.js +9 -0
- package/dist/@tool-jopinb/index.js.map +1 -0
- package/dist/@ui/components.d.ts +27 -0
- package/dist/@ui/components.js +42 -0
- package/dist/@ui/components.js.map +1 -0
- package/dist/@ui/cssModules.d.ts +11 -0
- package/dist/@ui/cssModules.js +17 -0
- package/dist/@ui/cssModules.js.map +1 -0
- package/dist/@ui/hooks.d.ts +31 -0
- package/dist/@ui/hooks.js +71 -0
- package/dist/@ui/hooks.js.map +1 -0
- package/dist/@ui/index.d.ts +9 -0
- package/dist/@ui/index.js +11 -0
- package/dist/@ui/index.js.map +1 -0
- package/dist/@ui/internal.d.ts +4 -0
- package/dist/@ui/internal.js +10 -0
- package/dist/@ui/internal.js.map +1 -0
- package/dist/@ui/modules.d.ts +41 -0
- package/dist/@ui/modules.js +74 -0
- package/dist/@ui/modules.js.map +1 -0
- package/dist/@ui/objectRegistry.d.ts +12 -0
- package/dist/@ui/objectRegistry.js +35 -0
- package/dist/@ui/objectRegistry.js.map +1 -0
- package/dist/@ui/pageController.d.ts +61 -0
- package/dist/@ui/pageController.js +166 -0
- package/dist/@ui/pageController.js.map +1 -0
- package/dist/@ui/tools.d.ts +24 -0
- package/dist/@ui/tools.js +78 -0
- package/dist/@ui/tools.js.map +1 -0
- package/dist/@uikit/core/UiKitModule.d.ts +6 -0
- package/dist/@uikit/core/UiKitModule.js +18 -0
- package/dist/@uikit/core/UiKitModule.js.map +1 -0
- package/dist/@uikit/core/index.d.ts +1 -0
- package/dist/@uikit/core/index.js +4 -0
- package/dist/@uikit/core/index.js.map +1 -0
- package/dist/@uikit/core/jBundler_ifBrowser.d.ts +1 -0
- package/dist/@uikit/core/jBundler_ifBrowser.js +5 -0
- package/dist/@uikit/core/jBundler_ifBrowser.js.map +1 -0
- package/dist/@uikit/core/jBundler_ifServer.d.ts +6 -0
- package/dist/@uikit/core/jBundler_ifServer.js +17 -0
- package/dist/@uikit/core/jBundler_ifServer.js.map +1 -0
- package/dist/@uikit/forms/components.d.ts +18 -0
- package/dist/@uikit/forms/components.js +69 -0
- package/dist/@uikit/forms/components.js.map +1 -0
- package/dist/@uikit/forms/hooks.d.ts +4 -0
- package/dist/@uikit/forms/hooks.js +31 -0
- package/dist/@uikit/forms/hooks.js.map +1 -0
- package/dist/@uikit/forms/index.d.ts +3 -0
- package/dist/@uikit/forms/index.js +4 -0
- package/dist/@uikit/forms/index.js.map +1 -0
- package/dist/@uikit/forms/interfaces.d.ts +101 -0
- package/dist/@uikit/forms/interfaces.js +4 -0
- package/dist/@uikit/forms/interfaces.js.map +1 -0
- package/dist/@uikit/forms/private.d.ts +40 -0
- package/dist/@uikit/forms/private.js +307 -0
- package/dist/@uikit/forms/private.js.map +1 -0
- package/dist/@uikit/helpers/hooks.d.ts +33 -0
- package/dist/@uikit/helpers/hooks.js +107 -0
- package/dist/@uikit/helpers/hooks.js.map +1 -0
- package/dist/@uikit/helpers/index.d.ts +2 -0
- package/dist/@uikit/helpers/index.js +3 -0
- package/dist/@uikit/helpers/index.js.map +1 -0
- package/dist/@uikit/helpers/tools.d.ts +8 -0
- package/dist/@uikit/helpers/tools.js +35 -0
- package/dist/@uikit/helpers/tools.js.map +1 -0
- package/dist/@uikit/index.d.ts +10 -0
- package/dist/@uikit/index.js +13 -0
- package/dist/@uikit/index.js.map +1 -0
- package/dist/@uikit/menu/core.d.ts +21 -0
- package/dist/@uikit/menu/core.js +191 -0
- package/dist/@uikit/menu/core.js.map +1 -0
- package/dist/@uikit/menu/hooks.d.ts +5 -0
- package/dist/@uikit/menu/hooks.js +24 -0
- package/dist/@uikit/menu/hooks.js.map +1 -0
- package/dist/@uikit/menu/index.d.ts +3 -0
- package/dist/@uikit/menu/index.js +4 -0
- package/dist/@uikit/menu/index.js.map +1 -0
- package/dist/@uikit/menu/interfaces.d.ts +20 -0
- package/dist/@uikit/menu/interfaces.js +8 -0
- package/dist/@uikit/menu/interfaces.js.map +1 -0
- package/dist/@uikit/menu/internal.d.ts +40 -0
- package/dist/@uikit/menu/internal.js +191 -0
- package/dist/@uikit/menu/internal.js.map +1 -0
- package/dist/@uikit/reactRouter/hooks/jBundler_ifBrowser.d.ts +18 -0
- package/dist/@uikit/reactRouter/hooks/jBundler_ifBrowser.js +40 -0
- package/dist/@uikit/reactRouter/hooks/jBundler_ifBrowser.js.map +1 -0
- package/dist/@uikit/reactRouter/hooks/jBundler_ifServer.d.ts +28 -0
- package/dist/@uikit/reactRouter/hooks/jBundler_ifServer.js +35 -0
- package/dist/@uikit/reactRouter/hooks/jBundler_ifServer.js.map +1 -0
- package/dist/@uikit/reactRouter/index.d.ts +1 -0
- package/dist/@uikit/reactRouter/index.js +2 -0
- package/dist/@uikit/reactRouter/index.js.map +1 -0
- package/dist/@uikit/users/hooks.d.ts +10 -0
- package/dist/@uikit/users/hooks.js +39 -0
- package/dist/@uikit/users/hooks.js.map +1 -0
- package/dist/@uikit/users/index.d.ts +1 -0
- package/dist/@uikit/users/index.js +2 -0
- package/dist/@uikit/users/index.js.map +1 -0
- package/dist/@uikit/variants/index.d.ts +7 -0
- package/dist/@uikit/variants/index.js +16 -0
- package/dist/@uikit/variants/index.js.map +1 -0
- package/package.json +115 -0
- package/src/@bundler/README.md +1 -0
- package/src/@bundler/_logs.ts +4 -0
- package/src/@bundler/core.ts +41 -0
- package/src/@bundler/esbuild.ts +141 -0
- package/src/@bundler/index.ts +3 -0
- package/src/@bundler/plugins.ts +163 -0
- package/src/@bundler/tailwind.ts +139 -0
- package/src/@core/PageComponent.tsx +25 -0
- package/src/@core/README.md +1 -0
- package/src/@core/_logs.ts +11 -0
- package/src/@core/automaticStartStop.ts +132 -0
- package/src/@core/browserCacheControl.ts +40 -0
- package/src/@core/bundler/bundler.ts +128 -0
- package/src/@core/bundler/common.ts +18 -0
- package/src/@core/bundler/config.ts +37 -0
- package/src/@core/bundler/extraContent.ts +30 -0
- package/src/@core/bundler/pagesGenerator.ts +194 -0
- package/src/@core/bundler/server.ts +41 -0
- package/src/@core/caches/InMemoryCache.ts +483 -0
- package/src/@core/caches/SimpleFileCache.ts +205 -0
- package/src/@core/caches/cache.ts +77 -0
- package/src/@core/caches/webSiteMirrorCache.ts +90 -0
- package/src/@core/cheerio.d.ts +332 -0
- package/src/@core/gzip.ts +33 -0
- package/src/@core/index.ts +23 -0
- package/src/@core/internalTools.ts +95 -0
- package/src/@core/jQuery.ts +22 -0
- package/src/@core/jopiEasy.ts +1285 -0
- package/src/@core/jopiRequest.tsx +1279 -0
- package/src/@core/jopiServer.ts +188 -0
- package/src/@core/jopiWebSite.tsx +1027 -0
- package/src/@core/letsEncrypt.ts +243 -0
- package/src/@core/linker.ts +42 -0
- package/src/@core/loadBalancing.ts +152 -0
- package/src/@core/middlewares/CorsMiddleware.ts +23 -0
- package/src/@core/middlewares/DdosProtection.ts +120 -0
- package/src/@core/middlewares/index.ts +16 -0
- package/src/@core/publicTools.ts +14 -0
- package/src/@core/routeConfig.ts +104 -0
- package/src/@core/searchParamFilter.ts +315 -0
- package/src/@core/serverFetch.ts +454 -0
- package/src/@core/serverImpl/server_bunjs.tsx +230 -0
- package/src/@core/serverImpl/server_nodejs.ts +312 -0
- package/src/@core/serverInstanceBuilder.ts +36 -0
- package/src/@core/userStores.ts +34 -0
- package/src/@crawler/README.md +1 -0
- package/src/@crawler/common.ts +275 -0
- package/src/@crawler/core.ts +678 -0
- package/src/@crawler/directFileCache.ts +69 -0
- package/src/@crawler/index.ts +4 -0
- package/src/@crawler/urlMapping.ts +67 -0
- package/src/@crawler/utils.ts +13 -0
- package/src/@generated/index.ts +134 -0
- package/src/@linker/arobaseTypes.ts +325 -0
- package/src/@linker/changeProof.ts +53 -0
- package/src/@linker/config.ts +46 -0
- package/src/@linker/engine.ts +865 -0
- package/src/@linker/index.ts +3 -0
- package/src/@linker/install.ts +39 -0
- package/src/@linker/modInstaller.ts +50 -0
- package/src/@linker/typeEvents.ts +58 -0
- package/src/@linker/typeRoutes.ts +255 -0
- package/src/@linker/typeUiComposite.ts +19 -0
- package/src/@loader/README.md +4 -0
- package/src/@loader/bunHtmlCompiler.mjs +27 -0
- package/src/@loader/index.ts +19 -0
- package/src/@loader/loader.mjs +7 -0
- package/src/@loader/nodeJsLoader.ts +21 -0
- package/src/@loader-client/README.md +2 -0
- package/src/@loader-client/index.ts +108 -0
- package/src/@loader-tools/README.md +6 -0
- package/src/@loader-tools/bunJsLoader.ts +33 -0
- package/src/@loader-tools/config.ts +142 -0
- package/src/@loader-tools/cssModuleCompiler.ts +76 -0
- package/src/@loader-tools/esBuildPlugin.ts +142 -0
- package/src/@loader-tools/index.ts +11 -0
- package/src/@loader-tools/jopin.ts +403 -0
- package/src/@loader-tools/nodeJsLoader.ts +119 -0
- package/src/@loader-tools/nodeJsResolver.ts +140 -0
- package/src/@loader-tools/rules.ts +45 -0
- package/src/@loader-tools/sourceChangesWatcher.ts +225 -0
- package/src/@loader-tools/tools.ts +139 -0
- package/src/@loader-tools/transform.ts +138 -0
- package/src/@loader-tools/virtualUrl.ts +57 -0
- package/src/@loader-types/README.md +15 -0
- package/src/@loader-types/extensions.d.ts +65 -0
- package/src/@tool-jopinb/README.md +1 -0
- package/src/@tool-jopinb/index.ts +11 -0
- package/src/@ui/README.md +3 -0
- package/src/@ui/components.tsx +49 -0
- package/src/@ui/cssModules.tsx +27 -0
- package/src/@ui/hooks.tsx +95 -0
- package/src/@ui/index.ts +13 -0
- package/src/@ui/internal.ts +12 -0
- package/src/@ui/modules.ts +100 -0
- package/src/@ui/objectRegistry.ts +50 -0
- package/src/@ui/pageController.ts +203 -0
- package/src/@ui/tools.ts +116 -0
- package/src/@uikit/README.md +1 -0
- package/src/@uikit/core/UiKitModule.ts +20 -0
- package/src/@uikit/core/index.ts +4 -0
- package/src/@uikit/core/jBundler_ifBrowser.ts +4 -0
- package/src/@uikit/core/jBundler_ifServer.ts +18 -0
- package/src/@uikit/forms/components.tsx +97 -0
- package/src/@uikit/forms/hooks.ts +38 -0
- package/src/@uikit/forms/index.ts +3 -0
- package/src/@uikit/forms/interfaces.ts +159 -0
- package/src/@uikit/forms/private.ts +365 -0
- package/src/@uikit/helpers/hooks.ts +133 -0
- package/src/@uikit/helpers/index.ts +2 -0
- package/src/@uikit/helpers/tools.ts +39 -0
- package/src/@uikit/index.ts +15 -0
- package/src/@uikit/menu/core.ts +227 -0
- package/src/@uikit/menu/hooks.ts +28 -0
- package/src/@uikit/menu/index.ts +3 -0
- package/src/@uikit/menu/interfaces.ts +26 -0
- package/src/@uikit/menu/internal.ts +218 -0
- package/src/@uikit/package.json +15 -0
- package/src/@uikit/reactRouter/hooks/jBundler_ifBrowser.tsx +59 -0
- package/src/@uikit/reactRouter/hooks/jBundler_ifServer.tsx +51 -0
- package/src/@uikit/reactRouter/index.ts +1 -0
- package/src/@uikit/users/hooks.ts +50 -0
- package/src/@uikit/users/index.ts +1 -0
- package/src/@uikit/variants/index.tsx +20 -0
|
@@ -0,0 +1,1027 @@
|
|
|
1
|
+
// noinspection JSUnusedGlobalSymbols
|
|
2
|
+
|
|
3
|
+
import {type FakeNoUserListener, JopiRequest} from "./jopiRequest.tsx";
|
|
4
|
+
import {ServerFetch} from "./serverFetch.ts";
|
|
5
|
+
import {LoadBalancer} from "./loadBalancing.ts";
|
|
6
|
+
import {type CoreServer, type SseEvent, type WebSocketConnectionInfos} from "./jopiServer.ts";
|
|
7
|
+
import {PostMiddlewares} from "./middlewares/index.ts";
|
|
8
|
+
import jwt from "jsonwebtoken";
|
|
9
|
+
import type {SearchParamFilterFunction} from "./searchParamFilter.ts";
|
|
10
|
+
import React from "react";
|
|
11
|
+
import {ModuleInitContext, type ModuleInitContext_Host, PageController, type UiUserInfos} from "jopijs/ui";
|
|
12
|
+
import type {PageCache} from "./caches/cache.ts";
|
|
13
|
+
import {VoidPageCache} from "./caches/cache.ts";
|
|
14
|
+
import {ONE_DAY} from "./publicTools.ts";
|
|
15
|
+
|
|
16
|
+
import {getInMemoryCache} from "./caches/InMemoryCache.ts";
|
|
17
|
+
import {installBundleServer} from "./bundler/server.ts";
|
|
18
|
+
import {createBundle} from "./bundler/bundler.ts";
|
|
19
|
+
import * as jk_webSocket from "jopi-toolkit/jk_webSocket";
|
|
20
|
+
import type {EventGroup} from "jopi-toolkit/jk_events";
|
|
21
|
+
import * as jk_events from "jopi-toolkit/jk_events";
|
|
22
|
+
import {installBrowserRefreshSseEvent, isBrowserRefreshEnabled} from "jopijs/loader-client";
|
|
23
|
+
import {executeBrowserInstall} from "./linker.ts";
|
|
24
|
+
import {getNewServerInstanceBuilder, type ServerInstanceBuilder} from "./serverInstanceBuilder.ts";
|
|
25
|
+
import {PriorityLevel, sortByPriority, type ValueWithPriority} from "jopi-toolkit/jk_tools";
|
|
26
|
+
import {logCache_notInCache, logServer_request} from "./_logs.ts";
|
|
27
|
+
import type {TryReturnFileParams} from "./browserCacheControl.ts";
|
|
28
|
+
|
|
29
|
+
export type RouteHandler = (req: JopiRequest) => Promise<Response>;
|
|
30
|
+
|
|
31
|
+
export interface MiddlewareOptions {
|
|
32
|
+
priority?: PriorityLevel;
|
|
33
|
+
regExp?: RegExp;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface WebSite {
|
|
37
|
+
data: any;
|
|
38
|
+
|
|
39
|
+
getWelcomeUrl(): string;
|
|
40
|
+
|
|
41
|
+
getCache(): PageCache;
|
|
42
|
+
|
|
43
|
+
setCache(pageCache: PageCache): void;
|
|
44
|
+
|
|
45
|
+
disableAutomaticCache(): void;
|
|
46
|
+
|
|
47
|
+
onPage(path: string, pageKey: string, reactComponent: React.FC<any>): WebSiteRouteInfos;
|
|
48
|
+
|
|
49
|
+
onVerb(verb: HttpMethod, path: string | string[], handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos;
|
|
50
|
+
|
|
51
|
+
onGET(path: string | string[], handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos;
|
|
52
|
+
|
|
53
|
+
onPOST(path: string | string[], handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos;
|
|
54
|
+
|
|
55
|
+
onPUT(path: string | string[], handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos;
|
|
56
|
+
|
|
57
|
+
onDELETE(path: string | string[], handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos;
|
|
58
|
+
|
|
59
|
+
onPATCH(path: string | string[], handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos;
|
|
60
|
+
|
|
61
|
+
onHEAD(path: string | string[], handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos;
|
|
62
|
+
|
|
63
|
+
onOPTIONS(path: string | string[], handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos;
|
|
64
|
+
|
|
65
|
+
onWebSocketConnect(path: string, handler: JopiWsRouteHandler): void;
|
|
66
|
+
|
|
67
|
+
addSseEVent(path: string|string[], handler: SseEvent): void;
|
|
68
|
+
|
|
69
|
+
on404_NotFound(handler: JopiRouteHandler): void;
|
|
70
|
+
return404(req: JopiRequest): Promise<Response>;
|
|
71
|
+
|
|
72
|
+
on500_Error(handler: JopiRouteHandler): void;
|
|
73
|
+
return500(req: JopiRequest, error?: any | string): Promise<Response>;
|
|
74
|
+
|
|
75
|
+
on401_Unauthorized(handler: JopiRouteHandler): void;
|
|
76
|
+
return401(req: JopiRequest, error?: Error | string): Promise<Response>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Try to authenticate a user.
|
|
80
|
+
*
|
|
81
|
+
* @param loginInfo
|
|
82
|
+
* Information about the user login/password.
|
|
83
|
+
* The real type is depending on what you use with the Website.setAuthHandler function.
|
|
84
|
+
*/
|
|
85
|
+
tryAuthUser<T = LoginPassword>(loginInfo: T): Promise<AuthResult>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Set the function which will verify user authentification
|
|
89
|
+
* and returns information about this user once connected.
|
|
90
|
+
*/
|
|
91
|
+
setAuthHandler<T>(authHandler: UserAuthentificationFunction<T>): void;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Create a JWT token with the data.
|
|
95
|
+
*/
|
|
96
|
+
createJwtToken(data: UserInfos): string | undefined;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Verify and decode the JWT token.
|
|
100
|
+
* Returns the data this token contains, or undefined if the token is invalid.
|
|
101
|
+
*/
|
|
102
|
+
decodeJwtToken(token: string): UserInfos | undefined;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Set the secret token for JWT cookies.
|
|
106
|
+
*/
|
|
107
|
+
setJwtSecret(secret: string): void;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Allow hooking how the JWT token is stored in the user response.
|
|
111
|
+
*/
|
|
112
|
+
setJwtTokenStore(store: JwtTokenStore): void;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* If you are using HTTPs, allow creating an HTTP website
|
|
116
|
+
* which will automatically redirect to the HTTP.
|
|
117
|
+
*/
|
|
118
|
+
getOrCreateHttpRedirectWebsite(): WebSite;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Ask to update the current SSL certificate.
|
|
122
|
+
* Will allow updating without restarting the server, nor losing connections.
|
|
123
|
+
* Warning: only works with bun.ts, node.ts implementation does nothing.
|
|
124
|
+
*/
|
|
125
|
+
updateSslCertificate(certificate: SslCertificatePath): void;
|
|
126
|
+
|
|
127
|
+
getHeadersToCache(): string[];
|
|
128
|
+
|
|
129
|
+
addHeaderToCache(header: string): void;
|
|
130
|
+
|
|
131
|
+
addGlobalMiddleware(method: HttpMethod|"*"|undefined, middleware: JopiMiddleware, options?: MiddlewareOptions): void;
|
|
132
|
+
addGlobalPostMiddleware(method: HttpMethod|"*"|undefined, middleware: JopiPostMiddleware, options?: MiddlewareOptions): void;
|
|
133
|
+
|
|
134
|
+
addSourceServer<T>(serverFetch: ServerFetch<T>, weight?: number): void;
|
|
135
|
+
|
|
136
|
+
enableCors(allows?: string[]): void;
|
|
137
|
+
|
|
138
|
+
readonly events: EventGroup;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface CacheRules {
|
|
142
|
+
regExp?: RegExp;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* If true, then disable the cache for the routes.
|
|
146
|
+
*/
|
|
147
|
+
disableAutomaticCache?: boolean;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Define a function which is called when the response is get from the cache.
|
|
151
|
+
* If a value is returned, then this value is used as the new value,
|
|
152
|
+
* allowing to replace what comes from the cache.
|
|
153
|
+
* @param handler
|
|
154
|
+
*/
|
|
155
|
+
afterGetFromCache?: (req: JopiRequest, res: Response) => Promise<Response | undefined | void>;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Defines a function which can alter the response to save into the cache or avoid cache adding.
|
|
159
|
+
* If returns a response: this response will be added into the cache.
|
|
160
|
+
* If returns undefined: will not add the response into the cache.
|
|
161
|
+
*/
|
|
162
|
+
beforeAddToCache?: (req: JopiRequest, res: Response) => Promise<Response | undefined | void>;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Define a function which is called before checking the cache.
|
|
166
|
+
* This allows doing some checking, and if needed, it can return
|
|
167
|
+
* a response and bypass the request cycle.
|
|
168
|
+
*/
|
|
169
|
+
beforeCheckingCache?: (req: JopiRequest) => Promise<Response | undefined | void>;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export class WebSiteImpl implements WebSite {
|
|
173
|
+
readonly port: number;
|
|
174
|
+
readonly host: string;
|
|
175
|
+
readonly welcomeUrl: string;
|
|
176
|
+
readonly isHttps?: boolean = false;
|
|
177
|
+
|
|
178
|
+
private http80WebSite?: WebSite;
|
|
179
|
+
certificate?: SslCertificatePath;
|
|
180
|
+
|
|
181
|
+
private globalMiddlewares: Record<string, {value: JopiMiddleware, priority: PriorityLevel, regExp?: RegExp}[]> = {};
|
|
182
|
+
private globalPostMiddlewares: Record<string, {value: JopiPostMiddleware, priority: PriorityLevel, regExp?: RegExp}[]> = {};
|
|
183
|
+
|
|
184
|
+
_onRebuildCertificate?: () => void;
|
|
185
|
+
private readonly _onWebSiteReady?: (() => void)[];
|
|
186
|
+
|
|
187
|
+
public readonly data: any = {};
|
|
188
|
+
|
|
189
|
+
public readonly loadBalancer = new LoadBalancer();
|
|
190
|
+
|
|
191
|
+
public readonly events: EventGroup = jk_events.defaultEventGroup;
|
|
192
|
+
|
|
193
|
+
public readonly mustRemoveTrailingSlashs: boolean;
|
|
194
|
+
|
|
195
|
+
constructor(url: string, options?: WebSiteOptions) {
|
|
196
|
+
if (!options) options = {};
|
|
197
|
+
|
|
198
|
+
url = url.trim().toLowerCase();
|
|
199
|
+
|
|
200
|
+
this.welcomeUrl = url;
|
|
201
|
+
this.certificate = options.certificate;
|
|
202
|
+
|
|
203
|
+
const urlInfos = new URL(url);
|
|
204
|
+
this.welcomeUrl = urlInfos.protocol + "//" + urlInfos.hostname;
|
|
205
|
+
|
|
206
|
+
if (urlInfos.protocol === "https:") this.isHttps = true;
|
|
207
|
+
else if (urlInfos.protocol!=="http:") throw new Error("invalid url");
|
|
208
|
+
|
|
209
|
+
if (urlInfos.port) {
|
|
210
|
+
this.port = parseInt(urlInfos.port);
|
|
211
|
+
this.welcomeUrl += ':' + this.port;
|
|
212
|
+
} else {
|
|
213
|
+
if (this.isHttps) this.port = 443;
|
|
214
|
+
else this.port = 80;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
this.host = urlInfos.host;
|
|
218
|
+
this.mainCache = options.cache || getInMemoryCache();
|
|
219
|
+
this.serverInstanceBuilder = getNewServerInstanceBuilder(this);
|
|
220
|
+
this.mustRemoveTrailingSlashs = options.removeTrailingSlash !== false;
|
|
221
|
+
|
|
222
|
+
this._onWebSiteReady = options.onWebSiteReady;
|
|
223
|
+
|
|
224
|
+
// Allow hooking the newly created websites.
|
|
225
|
+
jk_events.sendEvent("jopi.webSite.created", this);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
getWelcomeUrl(): string {
|
|
229
|
+
return this.welcomeUrl;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async processRequest(handler: RouteHandler|undefined, urlParts: any, routeInfos: WebSiteRouteInfos|undefined, urlInfos: URL|undefined, coreRequest: Request, coreServer: CoreServer): Promise<Response|undefined> {
|
|
233
|
+
// For security reasons. Without that, an attacker can break a cache.
|
|
234
|
+
if (urlInfos) urlInfos.hash = "";
|
|
235
|
+
|
|
236
|
+
const req = new JopiRequest(this, urlInfos, coreRequest, coreServer, routeInfos!);
|
|
237
|
+
req.urlParts = urlParts;
|
|
238
|
+
|
|
239
|
+
const endReq = logServer_request.beginInfo((w) => w(`${req.method} request`, {url: req.url }));
|
|
240
|
+
|
|
241
|
+
try {
|
|
242
|
+
let res: Response;
|
|
243
|
+
|
|
244
|
+
if (handler) {
|
|
245
|
+
res = await handler(req);
|
|
246
|
+
res = req._applyPostProcess(res);
|
|
247
|
+
} else {
|
|
248
|
+
res = await req.res_returnError404_NotFound();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
endReq({status: res.status});
|
|
252
|
+
return res;
|
|
253
|
+
} catch (e) {
|
|
254
|
+
if (e instanceof SBPE_ServerByPassException) {
|
|
255
|
+
if (e instanceof SBPE_DirectSendThisResponseException) {
|
|
256
|
+
if (e.response instanceof Response) {
|
|
257
|
+
return e.response;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
return await e.response(req);
|
|
261
|
+
}
|
|
262
|
+
} else if (e instanceof SBPE_NotAuthorizedException) {
|
|
263
|
+
return req.res_returnError401_Unauthorized();
|
|
264
|
+
} else if (e instanceof SBPE_MustReturnWithoutResponseException) {
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
console.error(e);
|
|
270
|
+
endReq({error: (e as Error).message});
|
|
271
|
+
|
|
272
|
+
return this.return500(req, e as Error | string);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async onBeforeServerStart() {
|
|
277
|
+
await jk_events.sendAsyncEvent("@jopi.server.before.start", {webSite: this});
|
|
278
|
+
await createBundle(this);
|
|
279
|
+
installBundleServer(this);
|
|
280
|
+
|
|
281
|
+
if (isBrowserRefreshEnabled()) {
|
|
282
|
+
// To known: there is a bug with some Chrome version
|
|
283
|
+
// doing that the SSE event is blocking the browser
|
|
284
|
+
// after 3/4 pages change through a link click
|
|
285
|
+
// (don't occur with a refresh)
|
|
286
|
+
//
|
|
287
|
+
installBrowserRefreshSseEvent(this);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async onServerStarted() {
|
|
292
|
+
if (this._onWebSiteReady) {
|
|
293
|
+
this._onWebSiteReady.forEach(e => e());
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (this.welcomeUrl) {
|
|
297
|
+
console.log("Website started:", this.welcomeUrl);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
addGlobalMiddleware(method: HttpMethod|"*"|undefined, middleware: JopiMiddleware, options: MiddlewareOptions) {
|
|
302
|
+
options = options || {};
|
|
303
|
+
|
|
304
|
+
let m = method ? method : "*";
|
|
305
|
+
if (!this.globalMiddlewares[m]) this.globalMiddlewares[m] = [];
|
|
306
|
+
this.globalMiddlewares[m].push({priority: options.priority||PriorityLevel.default, value: middleware, regExp: options.regExp});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
addGlobalPostMiddleware(method: HttpMethod|"*"|undefined, middleware: JopiPostMiddleware, options: MiddlewareOptions) {
|
|
310
|
+
options = options || {};
|
|
311
|
+
|
|
312
|
+
let m = method ? method : "*";
|
|
313
|
+
if (!this.globalPostMiddlewares[m]) this.globalPostMiddlewares[m] = [];
|
|
314
|
+
this.globalPostMiddlewares[m].push({priority: options.priority||PriorityLevel.default, value: middleware, regExp: options.regExp});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
addSourceServer<T>(serverFetch: ServerFetch<T>, weight?: number) {
|
|
318
|
+
this.loadBalancer.addServer<T>(serverFetch, weight);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
enableCors(allows?: string[]) {
|
|
322
|
+
if (!allows) allows = [this.welcomeUrl];
|
|
323
|
+
this.addGlobalPostMiddleware(undefined, PostMiddlewares.cors({accessControlAllowOrigin: allows}), {priority: PriorityLevel.veryHigh});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
applyMiddlewares(verb: HttpMethod, route: string, handler: JopiRouteHandler, isPage: boolean): JopiRouteHandler {
|
|
327
|
+
function merge<T>(a: T[]|undefined, b: T[]|undefined): T[]|undefined {
|
|
328
|
+
if (!a) return b;
|
|
329
|
+
if (!b) return a;
|
|
330
|
+
return a.concat(b);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function mergeMiddlewares(allMiddlewares: JopiMiddleware[]): JopiMiddleware|undefined {
|
|
334
|
+
if (allMiddlewares.length===0) return undefined;
|
|
335
|
+
if (allMiddlewares.length===1) return allMiddlewares[0];
|
|
336
|
+
|
|
337
|
+
const list = allMiddlewares.reverse();
|
|
338
|
+
let nextToCall: JopiMiddleware|undefined;
|
|
339
|
+
|
|
340
|
+
for (let m of list) {
|
|
341
|
+
if (nextToCall) {
|
|
342
|
+
const toCall = m;
|
|
343
|
+
const next = nextToCall;
|
|
344
|
+
|
|
345
|
+
nextToCall = async function(req) {
|
|
346
|
+
let res = toCall(req);
|
|
347
|
+
if (res instanceof Promise) res = await res;
|
|
348
|
+
if (res!==null) return res;
|
|
349
|
+
|
|
350
|
+
return next(req);
|
|
351
|
+
};
|
|
352
|
+
} else {
|
|
353
|
+
nextToCall = m;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return nextToCall;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function mergePostMiddlewares(allMiddlewares: JopiPostMiddleware[]): JopiPostMiddleware|undefined {
|
|
361
|
+
if (allMiddlewares.length===0) return undefined;
|
|
362
|
+
if (allMiddlewares.length===1) return allMiddlewares[0];
|
|
363
|
+
|
|
364
|
+
const list = allMiddlewares.reverse();
|
|
365
|
+
let nextToCall: JopiPostMiddleware|undefined;
|
|
366
|
+
|
|
367
|
+
for (let m of list) {
|
|
368
|
+
if (nextToCall) {
|
|
369
|
+
const toCall = m;
|
|
370
|
+
const next = nextToCall;
|
|
371
|
+
|
|
372
|
+
nextToCall = async function(req, res) {
|
|
373
|
+
let t = toCall(req, res);
|
|
374
|
+
if (t instanceof Promise) t = await t;
|
|
375
|
+
return next(req, t);
|
|
376
|
+
};
|
|
377
|
+
} else {
|
|
378
|
+
nextToCall = m;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return nextToCall;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
return async (req: JopiRequest) => {
|
|
387
|
+
const routeInfos = req.routeInfos;
|
|
388
|
+
|
|
389
|
+
const routeRawMiddlewares = routeInfos ? routeInfos.middlewares : undefined;
|
|
390
|
+
const routeRawPostMiddlewares = routeInfos ? routeInfos.postMiddlewares : undefined;
|
|
391
|
+
|
|
392
|
+
let globalRawMiddleware = this.globalMiddlewares[verb];
|
|
393
|
+
let globalRawPostMiddleware = this.globalPostMiddlewares[verb];
|
|
394
|
+
|
|
395
|
+
if (globalRawMiddleware) {
|
|
396
|
+
globalRawMiddleware = globalRawMiddleware.filter(m => {
|
|
397
|
+
if (m.regExp) {
|
|
398
|
+
return m.regExp.test(route);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return true;
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (globalRawPostMiddleware) {
|
|
406
|
+
globalRawPostMiddleware = globalRawPostMiddleware.filter(m => {
|
|
407
|
+
if (m.regExp) {
|
|
408
|
+
return m.regExp.test(route);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return true;
|
|
412
|
+
})
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
let middlewares = sortByPriority(merge(routeRawMiddlewares, globalRawMiddleware)) || [];
|
|
416
|
+
let postMiddlewares = sortByPriority(merge(routeRawPostMiddlewares, globalRawPostMiddleware)) || [];
|
|
417
|
+
|
|
418
|
+
// **********
|
|
419
|
+
|
|
420
|
+
const baseHandler = handler;
|
|
421
|
+
const mustUseAutoCache = this.mustUseAutomaticCache && routeInfos && (routeInfos.mustEnableAutomaticCache === true)
|
|
422
|
+
const extraMiddlewares: JopiMiddleware[] = [];
|
|
423
|
+
|
|
424
|
+
if (req.routeInfos.requiredRoles) {
|
|
425
|
+
const roles = req.routeInfos.requiredRoles;
|
|
426
|
+
|
|
427
|
+
extraMiddlewares.push((req: JopiRequest) => {
|
|
428
|
+
req.role_assertUserHasRoles(roles);
|
|
429
|
+
return null;
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (mustUseAutoCache) {
|
|
434
|
+
const beforeCheckingCache = routeInfos.beforeCheckingCache;
|
|
435
|
+
const afterGetFromCache = routeInfos.afterGetFromCache;
|
|
436
|
+
const beforeAddToCache = req.routeInfos.beforeAddToCache;
|
|
437
|
+
|
|
438
|
+
extraMiddlewares.push(async function () {
|
|
439
|
+
if (beforeCheckingCache) {
|
|
440
|
+
let r = await beforeCheckingCache(req);
|
|
441
|
+
//
|
|
442
|
+
if (r) {
|
|
443
|
+
return fPostMiddleware ? fPostMiddleware(req, r) : r;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
let res = await req.cache_getFromCache();
|
|
448
|
+
|
|
449
|
+
if (res) {
|
|
450
|
+
if (afterGetFromCache) {
|
|
451
|
+
const r = await afterGetFromCache(req, res);
|
|
452
|
+
//
|
|
453
|
+
if (r) {
|
|
454
|
+
return fPostMiddleware ? fPostMiddleware(req, r) : r;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return fPostMiddleware ? fPostMiddleware(req, res) : res;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
logCache_notInCache.info(w => w(`${req.method} request`, {url: req.urlInfos?.href}));
|
|
462
|
+
|
|
463
|
+
if (isPage) {
|
|
464
|
+
// Allows creating anonymous pages.
|
|
465
|
+
req.user_fakeNoUsers();
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// > Here we bypass the default workflow.
|
|
469
|
+
|
|
470
|
+
res = await baseHandler(req);
|
|
471
|
+
|
|
472
|
+
if (beforeAddToCache) {
|
|
473
|
+
let r = await beforeAddToCache(req, res);
|
|
474
|
+
if (r) return await req.cache_addToCache(r)!;
|
|
475
|
+
} else {
|
|
476
|
+
return await req.cache_addToCache(res)!;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
return res;
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
middlewares = [...extraMiddlewares, ...middlewares];
|
|
484
|
+
|
|
485
|
+
let newHandler: JopiRouteHandler;
|
|
486
|
+
|
|
487
|
+
const fMiddleware = mergeMiddlewares(middlewares);
|
|
488
|
+
const fPostMiddleware = mergePostMiddlewares(postMiddlewares);
|
|
489
|
+
|
|
490
|
+
if (fMiddleware || fPostMiddleware) {
|
|
491
|
+
newHandler = async (req: JopiRequest) => {
|
|
492
|
+
if (fMiddleware) {
|
|
493
|
+
const res = await fMiddleware(req);
|
|
494
|
+
if (res) return res;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const res = await baseHandler(req);
|
|
498
|
+
|
|
499
|
+
if (fPostMiddleware) {
|
|
500
|
+
return fPostMiddleware(req, res);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
return res;
|
|
504
|
+
};
|
|
505
|
+
} else {
|
|
506
|
+
newHandler = handler;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
req.routeInfos.handler = newHandler;
|
|
510
|
+
return await newHandler(req);
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
getOrCreateHttpRedirectWebsite(): WebSite {
|
|
515
|
+
if (this.http80WebSite) return this.http80WebSite;
|
|
516
|
+
if (this.port===80) return this;
|
|
517
|
+
|
|
518
|
+
let urlInfos = new URL(this.welcomeUrl);
|
|
519
|
+
urlInfos.port = "";
|
|
520
|
+
urlInfos.protocol = "http";
|
|
521
|
+
|
|
522
|
+
const webSite = new WebSiteImpl(urlInfos.href);
|
|
523
|
+
this.http80WebSite = webSite;
|
|
524
|
+
|
|
525
|
+
webSite.onGET("/**", async req => {
|
|
526
|
+
req.urlInfos.port = "";
|
|
527
|
+
req.urlInfos.protocol = "https";
|
|
528
|
+
|
|
529
|
+
return req.res_redirectResponse(true, req.urlInfos.href);
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
return webSite;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
updateSslCertificate(certificate: SslCertificatePath) {
|
|
536
|
+
this.certificate = certificate;
|
|
537
|
+
if (this._onRebuildCertificate) this._onRebuildCertificate();
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/*declareNewWebSocketConnection(jws: JopiWebSocket, infos: WebSocketConnectionInfos, urlInfos: URL) {
|
|
541
|
+
const matched = findRoute(this.wsRouter, "ws", urlInfos.pathname);
|
|
542
|
+
|
|
543
|
+
if (!matched) {
|
|
544
|
+
jws.close();
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
try { matched.data(jws, infos); }
|
|
549
|
+
catch(e) { console.error(e) }
|
|
550
|
+
}*/
|
|
551
|
+
|
|
552
|
+
onWebSocketConnect(path: string, handler: JopiWsRouteHandler) {
|
|
553
|
+
return this.serverInstanceBuilder.addWsRoute(path, handler);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
addSseEVent(path: string, handler: SseEvent): void {
|
|
557
|
+
this.serverInstanceBuilder.addSseEVent(path, handler);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
tryReturnFile(params: TryReturnFileParams): Promise<Response|undefined> {
|
|
561
|
+
return this.serverInstanceBuilder.tryReturnFile(params);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
//region UI Modules
|
|
565
|
+
|
|
566
|
+
executeBrowserInstall(pageController: PageController) {
|
|
567
|
+
executeBrowserInstall(this.createModuleInitInstance(pageController));
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Allow overriding the instance used by modules 'uiInit.tsx' files.
|
|
572
|
+
* @param instancier
|
|
573
|
+
*/
|
|
574
|
+
setModuleInitClassInstancier(instancier: (host: ModuleInitContext_Host) => ModuleInitContext) {
|
|
575
|
+
this.createModuleInitInstance = instancier;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
private createModuleInitInstance(pageController: ModuleInitContext_Host): ModuleInitContext {
|
|
579
|
+
// Note: this function will be replaced.
|
|
580
|
+
return new ModuleInitContext(pageController);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
//endregion
|
|
584
|
+
|
|
585
|
+
//region Cache
|
|
586
|
+
|
|
587
|
+
mainCache: PageCache;
|
|
588
|
+
fakeNoUser?: FakeNoUserListener;
|
|
589
|
+
mustUseAutomaticCache: boolean = true;
|
|
590
|
+
private cacheRules: CacheRules[] = [];
|
|
591
|
+
private headersToCache: string[] = ["content-type", "etag", "last-modified"];
|
|
592
|
+
|
|
593
|
+
getCache(): PageCache {
|
|
594
|
+
return this.mainCache;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
setCache(pageCache: PageCache) {
|
|
598
|
+
this.mainCache = pageCache || gVoidCache;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
disableAutomaticCache() {
|
|
602
|
+
this.mustUseAutomaticCache = false;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
getHeadersToCache(): string[] {
|
|
606
|
+
return this.headersToCache;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
addHeaderToCache(header: string) {
|
|
610
|
+
header = header.trim().toLowerCase();
|
|
611
|
+
if (!this.headersToCache.includes(header)) this.headersToCache.push(header);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
setCacheRules(rules: CacheRules[]) {
|
|
615
|
+
this.cacheRules = rules;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
setOnFakeNoUser(listener: FakeNoUserListener|undefined) {
|
|
619
|
+
this.fakeNoUser = listener;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
private applyCacheRules(routeInfos: WebSiteRouteInfos, path: string) {
|
|
623
|
+
for (let rule of this.cacheRules) {
|
|
624
|
+
if (rule.regExp) {
|
|
625
|
+
if (!rule.regExp.test(path)) continue;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
if (!routeInfos.afterGetFromCache) {
|
|
629
|
+
routeInfos.afterGetFromCache = rule.afterGetFromCache;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (!routeInfos.beforeAddToCache) {
|
|
633
|
+
routeInfos.beforeAddToCache = rule.beforeAddToCache;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (!routeInfos.beforeCheckingCache) {
|
|
637
|
+
routeInfos.beforeCheckingCache = rule.beforeCheckingCache;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
//endregion
|
|
643
|
+
|
|
644
|
+
//region JWT Token
|
|
645
|
+
|
|
646
|
+
private JWT_SECRET?: string;
|
|
647
|
+
private jwtSignInOptions?: jwt.SignOptions;
|
|
648
|
+
private authHandler?: UserAuthentificationFunction;
|
|
649
|
+
private jwtTokenStore?: JwtTokenStore;
|
|
650
|
+
|
|
651
|
+
public storeJwtToken(req: JopiRequest) {
|
|
652
|
+
const token = req.user_getJwtToken();
|
|
653
|
+
|
|
654
|
+
if (this.jwtTokenStore) {
|
|
655
|
+
this.jwtTokenStore(req.user_getJwtToken()!, "jwt " + token, req);
|
|
656
|
+
} else {
|
|
657
|
+
// Note: here we don't set the "Authorization" header, since it's an input-only header.
|
|
658
|
+
req.cookie_addCookieToRes("authorization", "jwt " + token, {maxAge: ONE_DAY * 7});
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
public setJwtTokenStore(store: JwtTokenStore) {
|
|
663
|
+
this.jwtTokenStore = store;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
createJwtToken(data: UserInfos): string|undefined {
|
|
667
|
+
try {
|
|
668
|
+
return jwt.sign(data as object, this.JWT_SECRET!, this.jwtSignInOptions);
|
|
669
|
+
} catch (e) {
|
|
670
|
+
console.error("createJwtToken", e);
|
|
671
|
+
return undefined;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
decodeJwtToken(token: string): UserInfos|undefined {
|
|
676
|
+
if (!this.JWT_SECRET) return undefined;
|
|
677
|
+
|
|
678
|
+
try { return jwt.verify(token, this.JWT_SECRET) as UserInfos; }
|
|
679
|
+
catch { return undefined; }
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
setJwtSecret(secret: string) {
|
|
683
|
+
this.JWT_SECRET = secret;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
async tryAuthUser<T = LoginPassword>(loginInfo: T): Promise<AuthResult> {
|
|
687
|
+
if (this.authHandler) {
|
|
688
|
+
const res = this.authHandler(loginInfo);
|
|
689
|
+
if (res instanceof Promise) return await res;
|
|
690
|
+
return res;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
return {isOk: false};
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
setAuthHandler<T>(authHandler: UserAuthentificationFunction<T>) {
|
|
697
|
+
this.authHandler = authHandler;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
//endregion
|
|
701
|
+
|
|
702
|
+
//region Routes processing
|
|
703
|
+
|
|
704
|
+
public readonly serverInstanceBuilder: ServerInstanceBuilder;
|
|
705
|
+
|
|
706
|
+
private _on404_NotFound?: JopiErrorHandler;
|
|
707
|
+
private _on500_Error?: JopiErrorHandler;
|
|
708
|
+
private _on401_Unauthorized?: JopiErrorHandler;
|
|
709
|
+
|
|
710
|
+
private allRouteInfos: Record<string, WebSiteRouteInfos> = {};
|
|
711
|
+
|
|
712
|
+
private saveRouteInfos(verb: string, route: string, routeInfos: WebSiteRouteInfos) {
|
|
713
|
+
this.allRouteInfos[verb + " " + route] = routeInfos;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
getRouteInfos(verb: string, route: string): WebSiteRouteInfos|undefined {
|
|
717
|
+
return this.allRouteInfos[verb + " " + route];
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
//region Path handler
|
|
721
|
+
|
|
722
|
+
onVerb(verb: HttpMethod, path: string, handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos {
|
|
723
|
+
handler = this.applyMiddlewares(verb, path, handler, false);
|
|
724
|
+
|
|
725
|
+
const routeInfos: WebSiteRouteInfos = {route: path, handler};
|
|
726
|
+
this.saveRouteInfos(verb, path, routeInfos);
|
|
727
|
+
|
|
728
|
+
this.serverInstanceBuilder.addRoute(verb, path, routeInfos);
|
|
729
|
+
|
|
730
|
+
if (verb==="GET") this.applyCacheRules(routeInfos, path);
|
|
731
|
+
return routeInfos;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
onPage(path: string, pageKey: string, reactComponent: React.FC<any>): WebSiteRouteInfos {
|
|
735
|
+
const routeInfos: WebSiteRouteInfos = {route: path, handler: gVoidRouteHandler};
|
|
736
|
+
this.saveRouteInfos("GET", path, routeInfos);
|
|
737
|
+
|
|
738
|
+
this.serverInstanceBuilder.addPage(path, pageKey, reactComponent, routeInfos);
|
|
739
|
+
|
|
740
|
+
// Cache is automatically enabled for pages.
|
|
741
|
+
routeInfos.mustEnableAutomaticCache = true;
|
|
742
|
+
|
|
743
|
+
return routeInfos;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
onGET(path: string, handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos {
|
|
747
|
+
return this.onVerb("GET", path, handler);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
onPOST(path: string, handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos {
|
|
751
|
+
return this.onVerb("POST", path, handler);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
onPUT(path: string, handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos {
|
|
755
|
+
return this.onVerb("PUT", path, handler);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
onDELETE(path: string, handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos {
|
|
759
|
+
return this.onVerb("DELETE", path, handler);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
onPATCH(path: string, handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos {
|
|
763
|
+
return this.onVerb("PATCH", path, handler);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
onHEAD(path: string, handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos {
|
|
767
|
+
return this.onVerb("HEAD", path, handler);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
onOPTIONS(path: string, handler: (req: JopiRequest) => Promise<Response>): WebSiteRouteInfos {
|
|
771
|
+
return this.onVerb("OPTIONS", path, handler);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
//endregion
|
|
775
|
+
|
|
776
|
+
//region Error handler
|
|
777
|
+
|
|
778
|
+
on404_NotFound(handler: JopiRouteHandler) {
|
|
779
|
+
this._on404_NotFound = handler;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
on500_Error(handler: JopiRouteHandler) {
|
|
783
|
+
this._on500_Error = handler;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
on401_Unauthorized(handler: JopiRouteHandler) {
|
|
787
|
+
this._on401_Unauthorized = handler;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
async return404(req: JopiRequest): Promise<Response> {
|
|
791
|
+
const accept = req.headers.get("accept");
|
|
792
|
+
if (!accept || !accept.startsWith("text/html")) return new Response("", {status: 404});
|
|
793
|
+
|
|
794
|
+
if (this._on404_NotFound) {
|
|
795
|
+
let res = await this._on404_NotFound(req);
|
|
796
|
+
if (res instanceof Promise) res = await res;
|
|
797
|
+
|
|
798
|
+
if (res) {
|
|
799
|
+
if (res.status !== 404) {
|
|
800
|
+
return new Response(res.body, {status: 404, headers: res.headers});
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
return res;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
return new Response("", {status: 404});
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
async return500(req: JopiRequest, error?: any|string): Promise<Response> {
|
|
811
|
+
const accept = req.headers.get("accept");
|
|
812
|
+
if (!accept || !accept.startsWith("text/html")) return new Response("", {status: 500});
|
|
813
|
+
|
|
814
|
+
if (this._on500_Error) {
|
|
815
|
+
// Avoid recursions.
|
|
816
|
+
req.res_returnError500_ServerError = async () => {
|
|
817
|
+
return new Response("Internal server error", {status: 500});
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
let res = this._on500_Error(req, error);
|
|
821
|
+
if (res instanceof Promise) res = await res;
|
|
822
|
+
|
|
823
|
+
if (res) {
|
|
824
|
+
if (res.status !== 500) {
|
|
825
|
+
return new Response(res.body, {status: 500, headers: res.headers});
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
return res;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
return new Response("", {status: 500});
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
async return401(req: JopiRequest, error?: Error|string): Promise<Response> {
|
|
836
|
+
if (this._on401_Unauthorized) {
|
|
837
|
+
let res = this._on401_Unauthorized(req, error);
|
|
838
|
+
if (res instanceof Promise) res = await res;
|
|
839
|
+
|
|
840
|
+
if (res) {
|
|
841
|
+
if (res.status !== 401) {
|
|
842
|
+
return new Response(res.body, {status: 401, headers: res.headers});
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
return res;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
if (req.method!=="GET") {
|
|
850
|
+
return new Response(error ? error.toString() : "", {status: 401});
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
return new Response("", {status: 401});
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
//endregion
|
|
857
|
+
|
|
858
|
+
//endregion
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
const gVoidRouteHandler = () => Promise.resolve(new Response("void", {status: 200}));
|
|
862
|
+
|
|
863
|
+
export interface ServeFileOptions {
|
|
864
|
+
/**
|
|
865
|
+
* If true, then /index.html is replaced by / in the browser nav bar.
|
|
866
|
+
* Default is true.
|
|
867
|
+
*/
|
|
868
|
+
replaceIndexHtml?: boolean;
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* If the request file is not found, then call this function.
|
|
872
|
+
* If undefined, then will directly return a 404 error.
|
|
873
|
+
*/
|
|
874
|
+
onNotFound?: (req: JopiRequest) => Response|Promise<Response>;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
export class WebSiteOptions {
|
|
878
|
+
/**
|
|
879
|
+
* The TLS certificate to use;
|
|
880
|
+
*/
|
|
881
|
+
certificate?: SslCertificatePath;
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Allow defining our own cache for this website and don't use the common one.
|
|
885
|
+
*/
|
|
886
|
+
cache?: PageCache;
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* A list of listeners which must be called when the website is fully operational.
|
|
890
|
+
*/
|
|
891
|
+
onWebSiteReady?: (()=>void)[];
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* If false, will remove the trailing-slash at the end of the urls.
|
|
895
|
+
* The default is true.
|
|
896
|
+
*/
|
|
897
|
+
removeTrailingSlash?: boolean;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
export interface WebSiteRouteInfos {
|
|
901
|
+
route: string;
|
|
902
|
+
handler: JopiRouteHandler;
|
|
903
|
+
|
|
904
|
+
middlewares?: ValueWithPriority<JopiMiddleware>[];
|
|
905
|
+
postMiddlewares?: ValueWithPriority<JopiPostMiddleware>[];
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* A list of roles which are required.
|
|
909
|
+
*/
|
|
910
|
+
requiredRoles?: string[];
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Define a filter to use to sanitize the search params of the url.
|
|
914
|
+
*/
|
|
915
|
+
searchParamFilter?: SearchParamFilterFunction;
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* If true, the automatic cache is enabled.
|
|
919
|
+
*/
|
|
920
|
+
mustEnableAutomaticCache?: boolean;
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Is executed before checking the cache.
|
|
924
|
+
* If a response is returned/void, then directly returns this response.
|
|
925
|
+
*/
|
|
926
|
+
beforeCheckingCache?: (req: JopiRequest) => Promise<Response|undefined|void>;
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* Is executed before adding the response to the cache.
|
|
930
|
+
* Returns the response or undefined/void to avoid adding to the cache.
|
|
931
|
+
*/
|
|
932
|
+
beforeAddToCache?: (req: JopiRequest, res: Response) => Promise<Response|undefined|void>;
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Is executed after getting the response from the cache.
|
|
936
|
+
* Returns the response or undefined/void to avoid using this cache entry.
|
|
937
|
+
*/
|
|
938
|
+
afterGetFromCache?: (req: JopiRequest, res: Response) => Promise<Response|undefined|void>;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
export class JopiWebSocket {
|
|
942
|
+
constructor(private readonly webSite: WebSite, private readonly server: CoreServer, private readonly webSocket: WebSocket) {
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
close(): void {
|
|
946
|
+
this.webSocket.close();
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
onMessage(listener: (msg: string|Buffer) => void): void {
|
|
950
|
+
jk_webSocket.onMessage(this.webSocket, listener);
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
sendMessage(msg: string|Buffer|Uint8Array|ArrayBuffer) {
|
|
954
|
+
jk_webSocket.sendMessage(this.webSocket, msg);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
export function newWebSite(url: string, options?: WebSiteOptions): WebSite {
|
|
959
|
+
return new WebSiteImpl(url, options);
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
export type JopiRouteHandler = (req: JopiRequest) => Promise<Response>;
|
|
963
|
+
export type JopiWsRouteHandler = (ws: JopiWebSocket, infos: WebSocketConnectionInfos) => void;
|
|
964
|
+
export type JopiErrorHandler = (req: JopiRequest, error?: Error|string) => Response|Promise<Response>;
|
|
965
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
966
|
+
export type RequestBody = ReadableStream<Uint8Array> | null;
|
|
967
|
+
export type SendingBody = ReadableStream<Uint8Array> | string | FormData | null;
|
|
968
|
+
|
|
969
|
+
export type ResponseModifier = (res: Response, req: JopiRequest) => Response|Promise<Response>;
|
|
970
|
+
export type TextModifier = (text: string, req: JopiRequest) => string|Promise<string>;
|
|
971
|
+
export type TestCookieValue = (value: string) => boolean|Promise<boolean>;
|
|
972
|
+
|
|
973
|
+
export type JwtTokenStore = (jwtToken: string, cookieValue: string, req: JopiRequest) => void;
|
|
974
|
+
export type UserAuthentificationFunction<T = any> = (loginInfo: T) => AuthResult|Promise<AuthResult>;
|
|
975
|
+
|
|
976
|
+
export type JopiMiddleware = (req: JopiRequest) => Response | Promise<Response|null> | null;
|
|
977
|
+
export type JopiPostMiddleware = (req: JopiRequest, res: Response) => Response | Promise<Response>;
|
|
978
|
+
|
|
979
|
+
export class SBPE_ServerByPassException extends Error {
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
export class SBPE_NotAuthorizedException extends SBPE_ServerByPassException {
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
export class SBPE_DirectSendThisResponseException extends SBPE_ServerByPassException {
|
|
986
|
+
constructor(public readonly response: Response| JopiRouteHandler) {
|
|
987
|
+
super();
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
export class SBPE_MustReturnWithoutResponseException extends SBPE_ServerByPassException {
|
|
992
|
+
constructor() {
|
|
993
|
+
super();
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
export class ServerAlreadyStartedError extends Error {
|
|
998
|
+
constructor() {
|
|
999
|
+
super("the server is already");
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
export interface CookieOptions {
|
|
1004
|
+
maxAge?: number;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
export interface UserInfos extends UiUserInfos {
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
export interface AuthResult {
|
|
1011
|
+
isOk: boolean;
|
|
1012
|
+
errorMessage?: string;
|
|
1013
|
+
authToken?: string;
|
|
1014
|
+
userInfos?: UserInfos;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
export interface SslCertificatePath {
|
|
1018
|
+
key: string;
|
|
1019
|
+
cert: string;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
export interface LoginPassword {
|
|
1023
|
+
login: string;
|
|
1024
|
+
password: string;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
const gVoidCache = new VoidPageCache();
|