@ohos-ports/layer0-prefetch 4.20.0-beta.0 → 4.20.0-beta.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/node_modules/@layer0/core/README.md +50 -0
- package/node_modules/@layer0/core/build.d.ts +5 -0
- package/node_modules/@layer0/core/build.js +17 -0
- package/node_modules/@layer0/core/cache/Cache.d.ts +56 -0
- package/node_modules/@layer0/core/cache/Cache.js +138 -0
- package/node_modules/@layer0/core/cache/CacheKey.d.ts +52 -0
- package/node_modules/@layer0/core/cache/CacheKey.js +95 -0
- package/node_modules/@layer0/core/config.d.ts +53 -0
- package/node_modules/@layer0/core/config.js +113 -0
- package/node_modules/@layer0/core/constants.d.ts +214 -0
- package/node_modules/@layer0/core/constants.js +216 -0
- package/node_modules/@layer0/core/context.d.ts +38 -0
- package/node_modules/@layer0/core/context.js +98 -0
- package/node_modules/@layer0/core/default-app/all/layer0.config.js +60 -0
- package/node_modules/@layer0/core/default-app/js/routes.js +27 -0
- package/node_modules/@layer0/core/default-app/ts/routes.ts +27 -0
- package/node_modules/@layer0/core/deploy/DeploymentBuilder.d.ts +177 -0
- package/node_modules/@layer0/core/deploy/DeploymentBuilder.js +543 -0
- package/node_modules/@layer0/core/deploy/bundle-esbuild.d.ts +11 -0
- package/node_modules/@layer0/core/deploy/bundle-esbuild.js +67 -0
- package/node_modules/@layer0/core/deploy/bundle-ncc.d.ts +8 -0
- package/node_modules/@layer0/core/deploy/bundle-ncc.js +30 -0
- package/node_modules/@layer0/core/deploy/bundle-nft.d.ts +7 -0
- package/node_modules/@layer0/core/deploy/bundle-nft.js +41 -0
- package/node_modules/@layer0/core/deploy/bundle-webpack.d.ts +11 -0
- package/node_modules/@layer0/core/deploy/bundle-webpack.js +127 -0
- package/node_modules/@layer0/core/deploy/index.d.ts +19 -0
- package/node_modules/@layer0/core/deploy/index.js +6 -0
- package/node_modules/@layer0/core/deploy/listSources.d.ts +11 -0
- package/node_modules/@layer0/core/deploy/listSources.js +18 -0
- package/node_modules/@layer0/core/deploy/paths.d.ts +27 -0
- package/node_modules/@layer0/core/deploy/paths.js +33 -0
- package/node_modules/@layer0/core/deploy/resolveInPackage.d.ts +7 -0
- package/node_modules/@layer0/core/deploy/resolveInPackage.js +21 -0
- package/node_modules/@layer0/core/deploy/routeToFiles.d.ts +14 -0
- package/node_modules/@layer0/core/deploy/routeToFiles.js +24 -0
- package/node_modules/@layer0/core/dev/DevServerOptions.d.ts +33 -0
- package/node_modules/@layer0/core/dev/DevServerOptions.js +2 -0
- package/node_modules/@layer0/core/dev/createDevServer.d.ts +8 -0
- package/node_modules/@layer0/core/dev/createDevServer.js +114 -0
- package/node_modules/@layer0/core/dev/index.d.ts +3 -0
- package/node_modules/@layer0/core/dev/index.js +6 -0
- package/node_modules/@layer0/core/dev/runLocalApp.d.ts +8 -0
- package/node_modules/@layer0/core/dev/runLocalApp.js +73 -0
- package/node_modules/@layer0/core/dev/serverlessCompatibilityMiddleware.d.ts +11 -0
- package/node_modules/@layer0/core/dev/serverlessCompatibilityMiddleware.js +30 -0
- package/node_modules/@layer0/core/edge/EdgeErrorPageResponseWriter.d.ts +12 -0
- package/node_modules/@layer0/core/edge/EdgeErrorPageResponseWriter.js +22 -0
- package/node_modules/@layer0/core/edge/EdgeResponseWriter.d.ts +122 -0
- package/node_modules/@layer0/core/edge/EdgeResponseWriter.js +451 -0
- package/node_modules/@layer0/core/edge/createEdgeConfig.d.ts +16 -0
- package/node_modules/@layer0/core/edge/createEdgeConfig.js +284 -0
- package/node_modules/@layer0/core/environment.d.ts +24 -0
- package/node_modules/@layer0/core/environment.js +42 -0
- package/node_modules/@layer0/core/errors/BackendFetchError.d.ts +11 -0
- package/node_modules/@layer0/core/errors/BackendFetchError.js +17 -0
- package/node_modules/@layer0/core/errors/FrameworkBuildError.d.ts +7 -0
- package/node_modules/@layer0/core/errors/FrameworkBuildError.js +26 -0
- package/node_modules/@layer0/core/index.d.ts +3 -0
- package/node_modules/@layer0/core/index.js +9 -0
- package/node_modules/@layer0/core/init/addToPackageJson.d.ts +7 -0
- package/node_modules/@layer0/core/init/addToPackageJson.js +22 -0
- package/node_modules/@layer0/core/init/index.d.ts +2 -0
- package/node_modules/@layer0/core/init/index.js +6 -0
- package/node_modules/@layer0/core/init/init.d.ts +5 -0
- package/node_modules/@layer0/core/init/init.js +17 -0
- package/node_modules/@layer0/core/lambda/JSBackend.d.ts +30 -0
- package/node_modules/@layer0/core/lambda/JSBackend.js +51 -0
- package/node_modules/@layer0/core/lambda/RequestListenerJSBackend.d.ts +8 -0
- package/node_modules/@layer0/core/lambda/RequestListenerJSBackend.js +19 -0
- package/node_modules/@layer0/core/lambda/adaptResponseEncodingToDownstream.d.ts +17 -0
- package/node_modules/@layer0/core/lambda/adaptResponseEncodingToDownstream.js +132 -0
- package/node_modules/@layer0/core/lambda/consoleWrapper.d.ts +16 -0
- package/node_modules/@layer0/core/lambda/consoleWrapper.js +127 -0
- package/node_modules/@layer0/core/lambda/getBodyLoggingData.d.ts +10 -0
- package/node_modules/@layer0/core/lambda/getBodyLoggingData.js +108 -0
- package/node_modules/@layer0/core/lambda/handler.d.ts +1 -0
- package/node_modules/@layer0/core/lambda/handler.js +91 -0
- package/node_modules/@layer0/core/lambda/handler.js.map +7 -0
- package/node_modules/@layer0/core/lambda/innerHandler.d.ts +7 -0
- package/node_modules/@layer0/core/lambda/innerHandler.js +181 -0
- package/node_modules/@layer0/core/lambda/lambdaInstance.d.ts +29 -0
- package/node_modules/@layer0/core/lambda/lambdaInstance.js +71 -0
- package/node_modules/@layer0/core/lambda/reqResMapper.d.ts +24 -0
- package/node_modules/@layer0/core/lambda/reqResMapper.js +286 -0
- package/node_modules/@layer0/core/lambda/stdStreamsWrapper.d.ts +31 -0
- package/node_modules/@layer0/core/lambda/stdStreamsWrapper.js +196 -0
- package/node_modules/@layer0/core/lambda/toJSBackend.d.ts +10 -0
- package/node_modules/@layer0/core/lambda/toJSBackend.js +23 -0
- package/node_modules/@layer0/core/node_modules/esbuild/LICENSE.md +21 -0
- package/node_modules/@layer0/core/node_modules/esbuild/README.md +3 -0
- package/node_modules/@layer0/core/node_modules/esbuild/bin/esbuild +223 -0
- package/node_modules/@layer0/core/node_modules/esbuild/install.js +301 -0
- package/node_modules/@layer0/core/node_modules/esbuild/lib/main.d.ts +716 -0
- package/node_modules/@layer0/core/node_modules/esbuild/lib/main.js +2532 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/README.md +3 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/bin/esbuild +0 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/esbuild.wasm +0 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/package.json +28 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/wasm_exec.js +575 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/wasm_exec_node.js +40 -0
- package/node_modules/@layer0/core/node_modules/esbuild/package.json +78 -0
- package/node_modules/@layer0/core/package.json +132 -0
- package/node_modules/@layer0/core/parser/parseRouter.d.ts +13 -0
- package/node_modules/@layer0/core/parser/parseRouter.js +77 -0
- package/node_modules/@layer0/core/plugins/PluginBase.d.ts +18 -0
- package/node_modules/@layer0/core/plugins/PluginBase.js +19 -0
- package/node_modules/@layer0/core/router/Backend.d.ts +69 -0
- package/node_modules/@layer0/core/router/Backend.js +176 -0
- package/node_modules/@layer0/core/router/BackendOptions.d.ts +11 -0
- package/node_modules/@layer0/core/router/BackendOptions.js +2 -0
- package/node_modules/@layer0/core/router/BaseResponseWriter.d.ts +65 -0
- package/node_modules/@layer0/core/router/BaseResponseWriter.js +81 -0
- package/node_modules/@layer0/core/router/BehindEdgeResponseWriterProxy.d.ts +4 -0
- package/node_modules/@layer0/core/router/BehindEdgeResponseWriterProxy.js +89 -0
- package/node_modules/@layer0/core/router/CacheManifest.d.ts +80 -0
- package/node_modules/@layer0/core/router/CacheManifest.js +83 -0
- package/node_modules/@layer0/core/router/CacheOptions.d.ts +171 -0
- package/node_modules/@layer0/core/router/CacheOptions.js +2 -0
- package/node_modules/@layer0/core/router/CustomCacheKey.d.ts +140 -0
- package/node_modules/@layer0/core/router/CustomCacheKey.js +272 -0
- package/node_modules/@layer0/core/router/GroupConfig.d.ts +7 -0
- package/node_modules/@layer0/core/router/GroupConfig.js +20 -0
- package/node_modules/@layer0/core/router/Groups.d.ts +7 -0
- package/node_modules/@layer0/core/router/Groups.js +21 -0
- package/node_modules/@layer0/core/router/Headers.d.ts +3 -0
- package/node_modules/@layer0/core/router/Headers.js +2 -0
- package/node_modules/@layer0/core/router/PathMatcher.d.ts +51 -0
- package/node_modules/@layer0/core/router/PathMatcher.js +73 -0
- package/node_modules/@layer0/core/router/Preload.d.ts +16 -0
- package/node_modules/@layer0/core/router/Preload.js +2 -0
- package/node_modules/@layer0/core/router/PreloadRequests.d.ts +23 -0
- package/node_modules/@layer0/core/router/PreloadRequests.js +66 -0
- package/node_modules/@layer0/core/router/Request.d.ts +74 -0
- package/node_modules/@layer0/core/router/Request.js +2 -0
- package/node_modules/@layer0/core/router/RequestContext.d.ts +12 -0
- package/node_modules/@layer0/core/router/RequestContext.js +11 -0
- package/node_modules/@layer0/core/router/Response.d.ts +55 -0
- package/node_modules/@layer0/core/router/Response.js +2 -0
- package/node_modules/@layer0/core/router/ResponseWriter.d.ts +1011 -0
- package/node_modules/@layer0/core/router/ResponseWriter.js +1341 -0
- package/node_modules/@layer0/core/router/Route.d.ts +124 -0
- package/node_modules/@layer0/core/router/Route.js +280 -0
- package/node_modules/@layer0/core/router/RouteCriteria.d.ts +68 -0
- package/node_modules/@layer0/core/router/RouteCriteria.js +2 -0
- package/node_modules/@layer0/core/router/RouteGroup.d.ts +157 -0
- package/node_modules/@layer0/core/router/RouteGroup.js +223 -0
- package/node_modules/@layer0/core/router/RouteGroupList.d.ts +45 -0
- package/node_modules/@layer0/core/router/RouteGroupList.js +73 -0
- package/node_modules/@layer0/core/router/Router.d.ts +439 -0
- package/node_modules/@layer0/core/router/Router.js +907 -0
- package/node_modules/@layer0/core/router/addBuiltInRoutes.d.ts +2 -0
- package/node_modules/@layer0/core/router/addBuiltInRoutes.js +58 -0
- package/node_modules/@layer0/core/router/addPreloadHeaders.d.ts +7 -0
- package/node_modules/@layer0/core/router/addPreloadHeaders.js +57 -0
- package/node_modules/@layer0/core/router/cacheManifestFromRouter.d.ts +6 -0
- package/node_modules/@layer0/core/router/cacheManifestFromRouter.js +85 -0
- package/node_modules/@layer0/core/router/createCustomCacheKey.d.ts +27 -0
- package/node_modules/@layer0/core/router/createCustomCacheKey.js +35 -0
- package/node_modules/@layer0/core/router/deriveSurrogateKeysFromJson.d.ts +36 -0
- package/node_modules/@layer0/core/router/deriveSurrogateKeysFromJson.js +70 -0
- package/node_modules/@layer0/core/router/index.d.ts +11 -0
- package/node_modules/@layer0/core/router/index.js +17 -0
- package/node_modules/@layer0/core/router/interpolateParams.d.ts +21 -0
- package/node_modules/@layer0/core/router/interpolateParams.js +150 -0
- package/node_modules/@layer0/core/router/loadRouter.d.ts +13 -0
- package/node_modules/@layer0/core/router/loadRouter.js +29 -0
- package/node_modules/@layer0/core/router/mergeQueryString.d.ts +1 -0
- package/node_modules/@layer0/core/router/mergeQueryString.js +23 -0
- package/node_modules/@layer0/core/router/normalizeCriteria.d.ts +6 -0
- package/node_modules/@layer0/core/router/normalizeCriteria.js +20 -0
- package/node_modules/@layer0/core/router/stream.d.ts +12 -0
- package/node_modules/@layer0/core/router/stream.js +30 -0
- package/node_modules/@layer0/core/router/universalRouteUtils.d.ts +55 -0
- package/node_modules/@layer0/core/router/universalRouteUtils.js +114 -0
- package/node_modules/@layer0/core/router/validateWriter.d.ts +41 -0
- package/node_modules/@layer0/core/router/validateWriter.js +120 -0
- package/node_modules/@layer0/core/serverless.yml +30 -0
- package/node_modules/@layer0/core/source.d.ts +9 -0
- package/node_modules/@layer0/core/source.js +17 -0
- package/node_modules/@layer0/core/test-utils/MockRequest.d.ts +15 -0
- package/node_modules/@layer0/core/test-utils/MockRequest.js +36 -0
- package/node_modules/@layer0/core/test-utils/MockResponse.d.ts +7 -0
- package/node_modules/@layer0/core/test-utils/MockResponse.js +24 -0
- package/node_modules/@layer0/core/test-utils/expect-extend.d.ts +1 -0
- package/node_modules/@layer0/core/test-utils/expect-extend.js +11 -0
- package/node_modules/@layer0/core/test-utils/index.d.ts +4 -0
- package/node_modules/@layer0/core/test-utils/index.js +11 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheBrowser.d.ts +19 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheBrowser.js +45 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheEdge.d.ts +19 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheEdge.js +38 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheServiceWorker.d.ts +19 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheServiceWorker.js +45 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeServedStale.d.ts +20 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeServedStale.js +50 -0
- package/node_modules/@layer0/core/test-utils/matchers/toHaveBody.d.ts +18 -0
- package/node_modules/@layer0/core/test-utils/matchers/toHaveBody.js +40 -0
- package/node_modules/@layer0/core/test-utils/matchers/toHaveHeader.d.ts +19 -0
- package/node_modules/@layer0/core/test-utils/matchers/toHaveHeader.js +43 -0
- package/node_modules/@layer0/core/test-utils/matchers.d.ts +6 -0
- package/node_modules/@layer0/core/test-utils/matchers.js +18 -0
- package/node_modules/@layer0/core/test-utils/utils/createRouteMock.d.ts +21 -0
- package/node_modules/@layer0/core/test-utils/utils/createRouteMock.js +27 -0
- package/node_modules/@layer0/core/test-utils/utils/getBackend.d.ts +13 -0
- package/node_modules/@layer0/core/test-utils/utils/getBackend.js +30 -0
- package/node_modules/@layer0/core/test-utils/utils/getMessage.d.ts +1 -0
- package/node_modules/@layer0/core/test-utils/utils/getMessage.js +16 -0
- package/node_modules/@layer0/core/test-utils/utils/runRoute.d.ts +10 -0
- package/node_modules/@layer0/core/test-utils/utils/runRoute.js +39 -0
- package/node_modules/@layer0/core/timing.d.ts +115 -0
- package/node_modules/@layer0/core/timing.js +200 -0
- package/node_modules/@layer0/core/transform/index.d.ts +1 -0
- package/node_modules/@layer0/core/transform/index.js +4 -0
- package/node_modules/@layer0/core/transform/transformMethod.d.ts +40 -0
- package/node_modules/@layer0/core/transform/transformMethod.js +58 -0
- package/node_modules/@layer0/core/types.d.ts +102 -0
- package/node_modules/@layer0/core/types.js +30 -0
- package/node_modules/@layer0/core/utils/Tasks.d.ts +32 -0
- package/node_modules/@layer0/core/utils/Tasks.js +80 -0
- package/node_modules/@layer0/core/utils/Validator.d.ts +18 -0
- package/node_modules/@layer0/core/utils/Validator.js +178 -0
- package/node_modules/@layer0/core/utils/bindParamsToPath.d.ts +15 -0
- package/node_modules/@layer0/core/utils/bindParamsToPath.js +49 -0
- package/node_modules/@layer0/core/utils/convertParamsToBackReferences.d.ts +16 -0
- package/node_modules/@layer0/core/utils/convertParamsToBackReferences.js +45 -0
- package/node_modules/@layer0/core/utils/convertStringMatcherToRegex.d.ts +7 -0
- package/node_modules/@layer0/core/utils/convertStringMatcherToRegex.js +26 -0
- package/node_modules/@layer0/core/utils/decode.d.ts +9 -0
- package/node_modules/@layer0/core/utils/decode.js +44 -0
- package/node_modules/@layer0/core/utils/esImport.d.ts +1 -0
- package/node_modules/@layer0/core/utils/esImport.js +9 -0
- package/node_modules/@layer0/core/utils/fs.d.ts +1 -0
- package/node_modules/@layer0/core/utils/fs.js +7 -0
- package/node_modules/@layer0/core/utils/get.d.ts +6 -0
- package/node_modules/@layer0/core/utils/get.js +19 -0
- package/node_modules/@layer0/core/utils/getPackageVersion.d.ts +7 -0
- package/node_modules/@layer0/core/utils/getPackageVersion.js +19 -0
- package/node_modules/@layer0/core/utils/has.d.ts +6 -0
- package/node_modules/@layer0/core/utils/has.js +15 -0
- package/node_modules/@layer0/core/utils/identity.d.ts +7 -0
- package/node_modules/@layer0/core/utils/identity.js +12 -0
- package/node_modules/@layer0/core/utils/index.d.ts +1 -0
- package/node_modules/@layer0/core/utils/index.js +4 -0
- package/node_modules/@layer0/core/utils/isEmpty.d.ts +6 -0
- package/node_modules/@layer0/core/utils/isEmpty.js +20 -0
- package/node_modules/@layer0/core/utils/isString.d.ts +1 -0
- package/node_modules/@layer0/core/utils/isString.js +6 -0
- package/node_modules/@layer0/core/utils/logo.d.ts +5 -0
- package/node_modules/@layer0/core/utils/logo.js +27 -0
- package/node_modules/@layer0/core/utils/mapValues.d.ts +7 -0
- package/node_modules/@layer0/core/utils/mapValues.js +16 -0
- package/node_modules/@layer0/core/utils/minBy.d.ts +8 -0
- package/node_modules/@layer0/core/utils/minBy.js +41 -0
- package/node_modules/@layer0/core/utils/nonWebpackRequire.d.ts +11 -0
- package/node_modules/@layer0/core/utils/nonWebpackRequire.js +28 -0
- package/node_modules/@layer0/core/utils/packageUtils.d.ts +12 -0
- package/node_modules/@layer0/core/utils/packageUtils.js +22 -0
- package/node_modules/@layer0/core/utils/ports.d.ts +5 -0
- package/node_modules/@layer0/core/utils/ports.js +7 -0
- package/node_modules/@layer0/core/utils/readBody.d.ts +7 -0
- package/node_modules/@layer0/core/utils/readBody.js +15 -0
- package/node_modules/@layer0/core/utils/readRawBody.d.ts +9 -0
- package/node_modules/@layer0/core/utils/readRawBody.js +21 -0
- package/node_modules/@layer0/core/utils/regExpEscape.d.ts +12 -0
- package/node_modules/@layer0/core/utils/regExpEscape.js +20 -0
- package/node_modules/@layer0/core/utils/requireInternal.d.ts +7 -0
- package/node_modules/@layer0/core/utils/requireInternal.js +24 -0
- package/node_modules/@layer0/core/utils/set.d.ts +10 -0
- package/node_modules/@layer0/core/utils/set.js +21 -0
- package/node_modules/@layer0/core/utils/toEdgeRegex.d.ts +11 -0
- package/node_modules/@layer0/core/utils/toEdgeRegex.js +23 -0
- package/node_modules/@layer0/core/utils/toHttpMethodMatchRegex.d.ts +12 -0
- package/node_modules/@layer0/core/utils/toHttpMethodMatchRegex.js +17 -0
- package/node_modules/@layer0/core/utils/toLower.d.ts +1 -0
- package/node_modules/@layer0/core/utils/toLower.js +9 -0
- package/node_modules/@layer0/core/utils/validateBackends.d.ts +5 -0
- package/node_modules/@layer0/core/utils/validateBackends.js +30 -0
- package/node_modules/@layer0/core/utils/watch.d.ts +10 -0
- package/node_modules/@layer0/core/utils/watch.js +17 -0
- package/package.json +47 -3
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import { PreloadRequestConfig } from './Preload';
|
|
2
|
+
import BackendOptions from './BackendOptions';
|
|
3
|
+
import PluginBase from '../plugins/PluginBase';
|
|
4
|
+
import PreloadRequests from './PreloadRequests';
|
|
5
|
+
import Request from './Request';
|
|
6
|
+
import Response from './Response';
|
|
7
|
+
import ResponseWriter from './ResponseWriter';
|
|
8
|
+
import RouteCriteria from './RouteCriteria';
|
|
9
|
+
import RouteGroup, { StaticOptions, BasicAuthOptions } from './RouteGroup';
|
|
10
|
+
import RouteGroupList from './RouteGroupList';
|
|
11
|
+
export interface RouterOptions {
|
|
12
|
+
/**
|
|
13
|
+
* If `true`, built in routes under /__layer0__/ will be not be added to the router.
|
|
14
|
+
*/
|
|
15
|
+
excludeBuiltInRoutes?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* If `true`, duplicate queries in request will not be transformed to array
|
|
18
|
+
*/
|
|
19
|
+
allowReqQueryDuplicates?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A router.
|
|
23
|
+
*/
|
|
24
|
+
export default class Router {
|
|
25
|
+
readonly routeGroups: RouteGroupList;
|
|
26
|
+
readonly preloadRequests: PreloadRequests;
|
|
27
|
+
readonly allowReqQueryDuplicates: boolean;
|
|
28
|
+
private readonly plugins;
|
|
29
|
+
private readonly destinations;
|
|
30
|
+
private nextRouterIndex;
|
|
31
|
+
private newRequestId?;
|
|
32
|
+
/**
|
|
33
|
+
* Index is used to determine the precedence of a router when routing rules
|
|
34
|
+
* have not resolved to a specific destination. The router with the lowest
|
|
35
|
+
* number wins.
|
|
36
|
+
* @private
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
private _index;
|
|
40
|
+
constructor(options?: RouterOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Returns a manifest of all static assets to be served via router.static
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
getStaticAssetManifest(): {
|
|
46
|
+
[key: string]: string[];
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Allows the lambda handler to add the __js__ backend in the cloud
|
|
50
|
+
* @private
|
|
51
|
+
* @param name
|
|
52
|
+
* @param value
|
|
53
|
+
*/
|
|
54
|
+
setBackend(name: string, value: BackendOptions): this;
|
|
55
|
+
/**
|
|
56
|
+
* Constructs plugin and pushes it to registered plugins
|
|
57
|
+
* @param pluginInstance A plugin to use.
|
|
58
|
+
* @returns {Router} A self-reference, suitable for chaining.
|
|
59
|
+
*/
|
|
60
|
+
use(pluginInstance: PluginBase): this;
|
|
61
|
+
/**
|
|
62
|
+
* Adds a named destination to which you can map traffic using the traffic shaping settings in your environment
|
|
63
|
+
* in Layer0 developer console
|
|
64
|
+
* @param name The name of the destination
|
|
65
|
+
* @param router A router to use when handling requests
|
|
66
|
+
* @returns {Router} A self-reference, suitable for chaining.
|
|
67
|
+
*/
|
|
68
|
+
destination(name: string, router: Router): this;
|
|
69
|
+
/**
|
|
70
|
+
* Returns all plugins, including those registered on destination routers.
|
|
71
|
+
*/
|
|
72
|
+
getPlugins(): PluginBase[];
|
|
73
|
+
/**
|
|
74
|
+
* Sets the index at which the router has been added to its parent router
|
|
75
|
+
* @private
|
|
76
|
+
* @param index
|
|
77
|
+
*/
|
|
78
|
+
setIndex(index: number): void;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the index at which the router has been added to its parent router
|
|
81
|
+
* @private
|
|
82
|
+
* @returns router's index
|
|
83
|
+
*/
|
|
84
|
+
get index(): number;
|
|
85
|
+
/**
|
|
86
|
+
* Adds a RouteGroup to router and calls route register function for group.
|
|
87
|
+
* @private
|
|
88
|
+
* @param name Group name
|
|
89
|
+
* @param registerRoutesFn Group route register function
|
|
90
|
+
* @returns {Router} A self-reference, suitable for chaining.
|
|
91
|
+
*/
|
|
92
|
+
group(name: string, registerRoutesFn: (group: RouteGroup) => void): this;
|
|
93
|
+
/**
|
|
94
|
+
* Adds a route matching all methods.
|
|
95
|
+
*
|
|
96
|
+
* Example:
|
|
97
|
+
*
|
|
98
|
+
* ```js
|
|
99
|
+
* new Router().match('/p/:productId', ({ cache, proxy }) => {
|
|
100
|
+
* cache({
|
|
101
|
+
* edge: {
|
|
102
|
+
* maxAgeSeconds: 60 * 60 * 24
|
|
103
|
+
* }
|
|
104
|
+
* })
|
|
105
|
+
*
|
|
106
|
+
* proxy('origin')
|
|
107
|
+
* })
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @param criteria Either the path as a string or an object with `path`, `method`, and `headers`.
|
|
111
|
+
* @param handler A handler function that will be called when the route is matched
|
|
112
|
+
* @returns {Router} A self-reference, suitable for chaining.
|
|
113
|
+
*/
|
|
114
|
+
match(criteria: RouteCriteria | string, handler: RouteHandler): this;
|
|
115
|
+
/**
|
|
116
|
+
* Adds preload config for router
|
|
117
|
+
*
|
|
118
|
+
* ```js
|
|
119
|
+
* new Router().preload(
|
|
120
|
+
* async () => [{ path: '/foo', headers: { foo: 'bar' } }],
|
|
121
|
+
* [{ path: '/bar' }]
|
|
122
|
+
* )
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @param preloadOptions
|
|
126
|
+
*/
|
|
127
|
+
prerender(...preloadOptions: Array<PreloadRequestConfig[] | (() => Promise<PreloadRequestConfig[]>) | (() => PreloadRequestConfig[])>): this;
|
|
128
|
+
/**
|
|
129
|
+
* Adds a route matching the given HTTP method.
|
|
130
|
+
*
|
|
131
|
+
* @param method HTTP method
|
|
132
|
+
* @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
|
|
133
|
+
* @param handler A handler function that will be called when the route is matched
|
|
134
|
+
* @private
|
|
135
|
+
*/
|
|
136
|
+
private matchMethod;
|
|
137
|
+
/**
|
|
138
|
+
* Adds a route matching `HEAD` HTTP method.
|
|
139
|
+
*
|
|
140
|
+
* @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
|
|
141
|
+
* @param handler A handler function that will be called when the route is matched
|
|
142
|
+
* @returns {Router} A self-reference, suitable for chaining.
|
|
143
|
+
*/
|
|
144
|
+
head(criteria: RouteCriteria | string, handler: RouteHandler): this;
|
|
145
|
+
/**
|
|
146
|
+
* Adds a route matching `GET` HTTP method.
|
|
147
|
+
*
|
|
148
|
+
* @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
|
|
149
|
+
* @param handler A handler function that will be called when the route is matched
|
|
150
|
+
* @returns {Router} A self-reference, suitable for chaining.
|
|
151
|
+
*/
|
|
152
|
+
get(criteria: RouteCriteria | string, handler: RouteHandler): this;
|
|
153
|
+
/**
|
|
154
|
+
* Adds a route matching `POST` HTTP method.
|
|
155
|
+
*
|
|
156
|
+
* @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
|
|
157
|
+
* @param handler A handler function that will be called when the route is matched
|
|
158
|
+
* @returns {Router} A self-reference, suitable for chaining.
|
|
159
|
+
*/
|
|
160
|
+
post(criteria: RouteCriteria | string, handler: RouteHandler): this;
|
|
161
|
+
/**
|
|
162
|
+
* Adds a route matching `DELETE` HTTP method.
|
|
163
|
+
*
|
|
164
|
+
* @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
|
|
165
|
+
* @param handler A handler function that will be called when the route is matched
|
|
166
|
+
* @returns {Router} A self-reference, suitable for chaining.
|
|
167
|
+
*/
|
|
168
|
+
delete(criteria: RouteCriteria | string, handler: RouteHandler): this;
|
|
169
|
+
/**
|
|
170
|
+
* Adds a route matching `PUT` HTTP method.
|
|
171
|
+
*
|
|
172
|
+
* @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
|
|
173
|
+
* @param handler A handler function that will be called when the route is matched
|
|
174
|
+
* @returns {Router} A self-reference, suitable for chaining.
|
|
175
|
+
*/
|
|
176
|
+
put(criteria: RouteCriteria | string, handler: RouteHandler): this;
|
|
177
|
+
/**
|
|
178
|
+
* Adds a route matching `PATCH` HTTP method.
|
|
179
|
+
*
|
|
180
|
+
* @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
|
|
181
|
+
* @param handler A handler function that will be called when the route is matched
|
|
182
|
+
* @returns {Router} A self-reference, suitable for chaining.
|
|
183
|
+
*/
|
|
184
|
+
patch(criteria: RouteCriteria | string, handler: RouteHandler): this;
|
|
185
|
+
/**
|
|
186
|
+
* Adds a route matching `OPTIONS` HTTP method.
|
|
187
|
+
*
|
|
188
|
+
* @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
|
|
189
|
+
* @param handler A handler function that will be called when the route is matched
|
|
190
|
+
* @returns {Router} A self-reference, suitable for chaining.
|
|
191
|
+
*/
|
|
192
|
+
options(criteria: RouteCriteria | string, handler: RouteHandler): this;
|
|
193
|
+
/**
|
|
194
|
+
* Adds a route that will run if no other routes are matched
|
|
195
|
+
* @param handler A handler function that will be called when no other route is matched
|
|
196
|
+
* @returns A self-reference, suitable for chaining.
|
|
197
|
+
*/
|
|
198
|
+
fallback(handler: RouteHandler): this;
|
|
199
|
+
/**
|
|
200
|
+
* Adds a route that matches all requests with internal error header.
|
|
201
|
+
* @param handler A handler function that will be called when the route is matched
|
|
202
|
+
* @returns {Router} A self-reference, suitable for chaining.
|
|
203
|
+
*/
|
|
204
|
+
catch(error: RegExp | string | number, handler: RouteHandler): this;
|
|
205
|
+
/**
|
|
206
|
+
* Disables crawling of permalinks by setting the `x-robots-tag: noindex` response header
|
|
207
|
+
* for hosts matching layer0.link or layer0-perma.link.
|
|
208
|
+
*
|
|
209
|
+
* ```js
|
|
210
|
+
* new Router().noIndexPermalink()
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* * @returns {Router} A self-reference, suitable for chaining.
|
|
214
|
+
*/
|
|
215
|
+
noIndexPermalink(): this;
|
|
216
|
+
/**
|
|
217
|
+
* Checks headers for validity and updates them as needed.
|
|
218
|
+
*
|
|
219
|
+
* Notes:
|
|
220
|
+
* - If x-request-id is not present we generate it and later inject it into
|
|
221
|
+
* the response.
|
|
222
|
+
* - If accept-encoding includes gzip then we use it but eliminating everything else
|
|
223
|
+
* as we don't support other encodings. If there is no gzip in accept-encoding
|
|
224
|
+
* then we delete it entirely forcing upstream to return uncoded response.
|
|
225
|
+
* - We emulate the edge router by injecting the same headers it injects:
|
|
226
|
+
* - x-0-client-ip
|
|
227
|
+
* - x-forwarded-for
|
|
228
|
+
*/
|
|
229
|
+
private processRequestHeaders;
|
|
230
|
+
/**
|
|
231
|
+
* Emulates edge by injecting device headers into the request prior to routing.
|
|
232
|
+
*
|
|
233
|
+
* Notes:
|
|
234
|
+
* - This code must be the same as the the generated edge router.
|
|
235
|
+
* - This code has been directly translated from ECL compiler
|
|
236
|
+
* - We emulate the edge router by injecting the same headers it injects:
|
|
237
|
+
* - x-0-device
|
|
238
|
+
* - x-0-vendor
|
|
239
|
+
* - x-0-browser
|
|
240
|
+
* - x-0-device-is-bot
|
|
241
|
+
*/
|
|
242
|
+
private processRequestDeviceHeaders;
|
|
243
|
+
/**
|
|
244
|
+
* Emulates edge by injecting Geolocation headers into the request prior to routing.
|
|
245
|
+
* - x-0-geo-city
|
|
246
|
+
* - x-0-geo-country-code
|
|
247
|
+
* - x-0-geo-latitude
|
|
248
|
+
* - x-0-geo-longitude
|
|
249
|
+
* - x-0-geo-postal-code
|
|
250
|
+
*/
|
|
251
|
+
private processRequestGeoHeaders;
|
|
252
|
+
/**
|
|
253
|
+
* Adds the `rawBody` (Buffer) and `body` (String) to the request
|
|
254
|
+
* @param req
|
|
255
|
+
*/
|
|
256
|
+
private processRequestBody;
|
|
257
|
+
/**
|
|
258
|
+
* Checks if the number of user headers is within the limits.
|
|
259
|
+
*
|
|
260
|
+
* Notes:
|
|
261
|
+
* - User headers are all those that do not have `x-0-` prefix.
|
|
262
|
+
* - We check user headers counts in the router because in local
|
|
263
|
+
* development the router is running on "the edge" and we want to
|
|
264
|
+
* simulate the edge behavior (which actually has hard limits on
|
|
265
|
+
* header count - see `LAYER0_MAX_USER_HEADERS_ALLOWED` for more info)
|
|
266
|
+
*/
|
|
267
|
+
private isUserHeaderCountWithinLimits;
|
|
268
|
+
/**
|
|
269
|
+
* Patches writeHead method of the response so that we can do any post-response work.
|
|
270
|
+
*
|
|
271
|
+
* Notes:
|
|
272
|
+
* - Injects response ID header when this same component has generated the request ID.
|
|
273
|
+
* All components that actually generate the request ID before processing the request
|
|
274
|
+
* or going upstream are then also responsible for sending back the request ID downstream.
|
|
275
|
+
* - Return status 542 when there are too many response headers.
|
|
276
|
+
*
|
|
277
|
+
* @param req The request
|
|
278
|
+
* @param res The response
|
|
279
|
+
*/
|
|
280
|
+
private patchResWriteHead;
|
|
281
|
+
/**
|
|
282
|
+
* Handles a request, sending the response by running the handler for each matched route.
|
|
283
|
+
* @param req The request
|
|
284
|
+
* @param res The response
|
|
285
|
+
*/
|
|
286
|
+
run: (req: Request, res: Response) => Promise<void>;
|
|
287
|
+
/**
|
|
288
|
+
* Both edge and @core/router have a built-in fallback that has the following rules:
|
|
289
|
+
*
|
|
290
|
+
* 1. On HTTP protocol return a 301 with the same request path in `location` header but on HTTPS
|
|
291
|
+
* protocol.
|
|
292
|
+
* 2. On HTTPS protocol return a 404.
|
|
293
|
+
*
|
|
294
|
+
* One complication is that in local development HTTPS does not exist - it is only emulated.
|
|
295
|
+
* Therefore in local development we could go into a redirect loop if the HTTP is emulated
|
|
296
|
+
* through the `local_layer0_emulate_http_protocol` cookie. There are a few options:
|
|
297
|
+
*
|
|
298
|
+
* 1. Always return 404 in local development.
|
|
299
|
+
* 2. If the cookie is present, issue 301 but unset the cookie in the response.
|
|
300
|
+
* 3. If the cookie is not present, return 301.
|
|
301
|
+
*
|
|
302
|
+
* We feel that the least surprising is simply always issuing 404 as that is also the original behavior.
|
|
303
|
+
*
|
|
304
|
+
* @param res
|
|
305
|
+
*/
|
|
306
|
+
private builtInFallback;
|
|
307
|
+
/**
|
|
308
|
+
* Adds routes for all static assets in a directory tree.
|
|
309
|
+
*
|
|
310
|
+
* **Example**
|
|
311
|
+
*
|
|
312
|
+
* ```js
|
|
313
|
+
* router.static('public')
|
|
314
|
+
* ```
|
|
315
|
+
*
|
|
316
|
+
* To only serve files matching a particular pattern, use the `glob` options:
|
|
317
|
+
*
|
|
318
|
+
* ```js
|
|
319
|
+
* router.static('public', {
|
|
320
|
+
* glob: '*.css'
|
|
321
|
+
* })
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* By default the path on which files are served corresponds to the path within the directory,
|
|
325
|
+
* so for example, `public/css/main.css` would be served at `'/css/main.css'`,
|
|
326
|
+
* you can override this using the `path` option:
|
|
327
|
+
*
|
|
328
|
+
* ```js
|
|
329
|
+
* router.static('public', {
|
|
330
|
+
* paths: file => ['/assets/ + file] // will serve public/css/main.css at /assets/css/main.css
|
|
331
|
+
* })
|
|
332
|
+
* ```
|
|
333
|
+
*
|
|
334
|
+
* You can add caching or other additional handler logic using the `handler` option:
|
|
335
|
+
*
|
|
336
|
+
* ```js
|
|
337
|
+
* router.static('public', {
|
|
338
|
+
* handler: (file) => ({ cache }) => {
|
|
339
|
+
* cache({
|
|
340
|
+
* browser: {
|
|
341
|
+
* maxAgeSeconds: 60 * 60
|
|
342
|
+
* },
|
|
343
|
+
* edge: {
|
|
344
|
+
* maxAgeSeconds: 60 * 60 * 24,
|
|
345
|
+
* staleWhileRevalidateSeconds: 60 * 60
|
|
346
|
+
* }
|
|
347
|
+
* })
|
|
348
|
+
* }
|
|
349
|
+
* })
|
|
350
|
+
* ```
|
|
351
|
+
*
|
|
352
|
+
* @param sourcePath The path to a directory containing static assets relative to the root of your project.
|
|
353
|
+
* @param options
|
|
354
|
+
* @returns A self-reference, suitable for chaining.
|
|
355
|
+
*/
|
|
356
|
+
static(sourcePath: string, options?: StaticOptions): this;
|
|
357
|
+
/**
|
|
358
|
+
* Shorthand for adding GraphQL body matching
|
|
359
|
+
*
|
|
360
|
+
* Examples:
|
|
361
|
+
*
|
|
362
|
+
* // by default the path is graphql
|
|
363
|
+
* new Router().graphqlOperation("GetRates")
|
|
364
|
+
*
|
|
365
|
+
* or
|
|
366
|
+
*
|
|
367
|
+
* // with optional non-default path
|
|
368
|
+
* new Router().graphqlOperation({ path: "/gql-api", name: "GetRates" })
|
|
369
|
+
*
|
|
370
|
+
* @param criteria Either the operation name as a string or an object with `path`, `name`.
|
|
371
|
+
* @param handler A handler function that will be called when the route is matched
|
|
372
|
+
*
|
|
373
|
+
* @returns A self-reference, suitable for chaining.
|
|
374
|
+
*/
|
|
375
|
+
graphqlOperation(criteria: string | RegExp | {
|
|
376
|
+
path: string;
|
|
377
|
+
name: string | RegExp;
|
|
378
|
+
}, handler: RouteHandler): this;
|
|
379
|
+
/**
|
|
380
|
+
* Adds Basic Authentication.
|
|
381
|
+
*
|
|
382
|
+
* **example**
|
|
383
|
+
*
|
|
384
|
+
* ```js
|
|
385
|
+
* router
|
|
386
|
+
* .requireBasicAuth({ username: 'user', password: 's3cr3t!' })
|
|
387
|
+
* // ...include additional routes below...
|
|
388
|
+
* ```
|
|
389
|
+
*
|
|
390
|
+
* You can also require basic auth for a subset of URLs using the `criteria` option:
|
|
391
|
+
*
|
|
392
|
+
* ```js
|
|
393
|
+
* router
|
|
394
|
+
* .requireBasicAuth({ criteria: '/secret/:path*', username: 'user', password: 's3cr3t!' })
|
|
395
|
+
* // ...include additional routes below...
|
|
396
|
+
* ```
|
|
397
|
+
*
|
|
398
|
+
* The criteria option accepts a path pattern as a string, or a RouteCriteria object.
|
|
399
|
+
*
|
|
400
|
+
* @param options
|
|
401
|
+
* @returns A self-reference, suitable for chaining.
|
|
402
|
+
*/
|
|
403
|
+
requireBasicAuth(options: BasicAuthOptions): this;
|
|
404
|
+
/**
|
|
405
|
+
* Returns edge config from current router
|
|
406
|
+
* @private
|
|
407
|
+
*/
|
|
408
|
+
createEdgeConfig(): Promise<import("../types").EdgeConfig>;
|
|
409
|
+
/**
|
|
410
|
+
* Returns preload config from current router
|
|
411
|
+
* @private
|
|
412
|
+
*/
|
|
413
|
+
createPreloadConfig(): Promise<import("./Preload").CompiledPreloadOptions>;
|
|
414
|
+
/**
|
|
415
|
+
* @private
|
|
416
|
+
*/
|
|
417
|
+
getDestinations(): {
|
|
418
|
+
[name: string]: Router;
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* @private
|
|
422
|
+
*/
|
|
423
|
+
getRouteGroups(): RouteGroupList;
|
|
424
|
+
/**
|
|
425
|
+
* Returns a string summarizing all routes for debugging purposes. Don't rely on the format
|
|
426
|
+
* of this string as we may improve it over time.
|
|
427
|
+
*/
|
|
428
|
+
toString(): string;
|
|
429
|
+
/**
|
|
430
|
+
* Returns true if the request came through Layer0 edge.
|
|
431
|
+
*
|
|
432
|
+
* Notes:
|
|
433
|
+
* - If the request came through Layer0 edge then `x-0-version` has been injected.
|
|
434
|
+
*
|
|
435
|
+
* @param req The request
|
|
436
|
+
*/
|
|
437
|
+
static isRequestFromEdge(req: Request): boolean;
|
|
438
|
+
}
|
|
439
|
+
export declare type RouteHandler = (respond: ResponseWriter) => void;
|