@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,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ohos-ports/esbuild",
|
|
3
|
+
"version": "0.28.1-beta.2",
|
|
4
|
+
"description": "An extremely fast JavaScript and CSS bundler and minifier.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
8
|
+
"directory": "ports/@turbo/gen/2.11.7"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"postinstall": "node install.js"
|
|
12
|
+
},
|
|
13
|
+
"main": "lib/main.js",
|
|
14
|
+
"types": "lib/main.d.ts",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=18"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"esbuild": "bin/esbuild"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ohos-ports/esbuild-openharmony-arm64": "0.28.1-beta.5"
|
|
23
|
+
},
|
|
24
|
+
"optionalDependencies": {
|
|
25
|
+
"@esbuild/aix-ppc64": "0.28.1",
|
|
26
|
+
"@esbuild/android-arm": "0.28.1",
|
|
27
|
+
"@esbuild/android-arm64": "0.28.1",
|
|
28
|
+
"@esbuild/android-x64": "0.28.1",
|
|
29
|
+
"@esbuild/darwin-arm64": "0.28.1",
|
|
30
|
+
"@esbuild/darwin-x64": "0.28.1",
|
|
31
|
+
"@esbuild/freebsd-arm64": "0.28.1",
|
|
32
|
+
"@esbuild/freebsd-x64": "0.28.1",
|
|
33
|
+
"@esbuild/linux-arm": "0.28.1",
|
|
34
|
+
"@esbuild/linux-arm64": "0.28.1",
|
|
35
|
+
"@esbuild/linux-ia32": "0.28.1",
|
|
36
|
+
"@esbuild/linux-loong64": "0.28.1",
|
|
37
|
+
"@esbuild/linux-mips64el": "0.28.1",
|
|
38
|
+
"@esbuild/linux-ppc64": "0.28.1",
|
|
39
|
+
"@esbuild/linux-riscv64": "0.28.1",
|
|
40
|
+
"@esbuild/linux-s390x": "0.28.1",
|
|
41
|
+
"@esbuild/linux-x64": "0.28.1",
|
|
42
|
+
"@esbuild/netbsd-arm64": "0.28.1",
|
|
43
|
+
"@esbuild/netbsd-x64": "0.28.1",
|
|
44
|
+
"@esbuild/openbsd-arm64": "0.28.1",
|
|
45
|
+
"@esbuild/openbsd-x64": "0.28.1",
|
|
46
|
+
"@ohos-ports/esbuild-openharmony-arm64": "0.28.1-beta.5",
|
|
47
|
+
"@esbuild/sunos-x64": "0.28.1",
|
|
48
|
+
"@esbuild/win32-arm64": "0.28.1",
|
|
49
|
+
"@esbuild/win32-ia32": "0.28.1",
|
|
50
|
+
"@esbuild/win32-x64": "0.28.1"
|
|
51
|
+
},
|
|
52
|
+
"license": "MIT",
|
|
53
|
+
"esbuild.binaryHashes": {
|
|
54
|
+
"@esbuild/aix-ppc64/bin/esbuild": "0dd860154344f94b7a9367e64ffc2bc5b89a4313b4a399e5127cdc4ff5000303",
|
|
55
|
+
"@esbuild/android-arm64/bin/esbuild": "087671da02d323e7915fafc13567c0929192633ed544bd8adee9bc020fddf5b4",
|
|
56
|
+
"@esbuild/darwin-arm64/bin/esbuild": "e2dc9a52440a2a34f09434a2f4843cb1e30f84e40dcf238976ec61ef8cd7f36a",
|
|
57
|
+
"@esbuild/darwin-x64/bin/esbuild": "dd53ccf32f9b5b3ab30d41388ef1fc8f81c44ca57ee7a32a7364a1753308d009",
|
|
58
|
+
"@esbuild/freebsd-arm64/bin/esbuild": "5fef5a5ef24d9660d7711b756be5ddeba1fb3ca8dd62d703682ebb9fab3b68b0",
|
|
59
|
+
"@esbuild/freebsd-x64/bin/esbuild": "4427a8cbfa0661943ccfef2606a65b35f3411ac73e447e86f7732aace61e4609",
|
|
60
|
+
"@esbuild/linux-arm/bin/esbuild": "a2d93f7a8b1c9f91d47beec987888b4765c890501b6274f4bdff4061a5e0d9fd",
|
|
61
|
+
"@esbuild/linux-arm64/bin/esbuild": "51e829ba36f36be6d9aea6e329ddc4f9350302339b16aaca96a3cb97f64a8ebb",
|
|
62
|
+
"@esbuild/linux-ia32/bin/esbuild": "9cd7515a75d6f96b0aa055861cf987498315428088cd6d18de5082f904ae5794",
|
|
63
|
+
"@esbuild/linux-loong64/bin/esbuild": "73fa76af9b13f7a27fdb20673b8c2af927fe1511d14e51edeb4b7b71f7f03d0e",
|
|
64
|
+
"@esbuild/linux-mips64el/bin/esbuild": "d734787abc3c99d95242805047fe32da85a5822f04bf33d766a966bf5fd85488",
|
|
65
|
+
"@esbuild/linux-ppc64/bin/esbuild": "90709144617c2adf8f6c14937f03b114c259de0b9309666e3a9d89a1fb266d04",
|
|
66
|
+
"@esbuild/linux-riscv64/bin/esbuild": "86df35a46bedde8b756edb6565a1df7b5a832ad74dd0e179608cbf6509a2582a",
|
|
67
|
+
"@esbuild/linux-s390x/bin/esbuild": "f8cad0db35132e5ac3065c4345c36e7ffe18fdc98417a61bcf5a95a6c694e57c",
|
|
68
|
+
"@esbuild/linux-x64/bin/esbuild": "0c6588b092a2c291a72bab90659f3c9e0e25e0fe59c9ac12b4dae4d945e5548c",
|
|
69
|
+
"@esbuild/netbsd-arm64/bin/esbuild": "490cfdac2d96d5608d91cf55bdf4052bbde7013dafe87ec7adc7784778ad4d4c",
|
|
70
|
+
"@esbuild/netbsd-x64/bin/esbuild": "c61e0e4c553a4986fd0e9d63a0425e93be831ff7b13bfb8a564368fb7590f85d",
|
|
71
|
+
"@esbuild/openbsd-arm64/bin/esbuild": "f9d814698e26c09c3f90d4c103cbdf3832c9f2c841d64a93889d63d23da9b8cf",
|
|
72
|
+
"@esbuild/openbsd-x64/bin/esbuild": "2e30dce11f7236aa362c1c57212cc696f51472169aa417f30e9b641f3b7dcade",
|
|
73
|
+
"@esbuild/sunos-x64/bin/esbuild": "770e0d2bc930b1a1d19d3f43243ff8f393efddb599e7f5843160feacd253267d",
|
|
74
|
+
"@esbuild/win32-arm64/esbuild.exe": "bfb8798ab678f1ce4a723739f4a3eabab3244d7a04eeb12be2eb9f58095c13ef",
|
|
75
|
+
"@esbuild/win32-ia32/esbuild.exe": "8fa99b6e0945830fce8d7e208fdb21763aa4aea875751f4a0eec7f6e262af1dd",
|
|
76
|
+
"@esbuild/win32-x64/esbuild.exe": "ec02ee9b14ab332416fedd10614dfb80eed5304d94f67745067c011934a8c3c3"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@layer0/core",
|
|
3
|
+
"version": "4.20.0",
|
|
4
|
+
"main": "./index.js",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"docs": "typedoc",
|
|
8
|
+
"build": "rm -rf ./dist; mkdir ./dist; cp -r package.json README.md serverless.yml default-app ./dist; tsc; npm run bundle-handler;",
|
|
9
|
+
"bundle-handler": "esbuild src/lambda/handler.ts --bundle --minify --platform=node --target=node14.0 --outfile=dist/lambda/handler.js --log-level=error --sourcemap",
|
|
10
|
+
"watch": "npm-watch",
|
|
11
|
+
"ts:watch": "tsc --watch",
|
|
12
|
+
"push-build": "npm run build && cd dist && yalc push --force && cd ..",
|
|
13
|
+
"release": "cd ./dist; npm publish --access public",
|
|
14
|
+
"release:next": "npm run release -- --tag next",
|
|
15
|
+
"test": "jest --watchAll=false --runInBand --forceExit"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@babel/parser": "^7.18.9",
|
|
19
|
+
"@babel/traverse": "^7.18.9",
|
|
20
|
+
"@types/lodash.clonedeep": "^4.5.6",
|
|
21
|
+
"ajv": "^6.12.6",
|
|
22
|
+
"babel-loader": "^8.2.2",
|
|
23
|
+
"chalk": "^4.1.2",
|
|
24
|
+
"chardet": "^1.4.0",
|
|
25
|
+
"chokidar": "^3.5.1",
|
|
26
|
+
"cls-hooked": "^4.2.2",
|
|
27
|
+
"content-type": "^1.0.4",
|
|
28
|
+
"cookie": "^0.4.1",
|
|
29
|
+
"cross-spawn": "^7.0.3",
|
|
30
|
+
"decode-uri-component": "^0.2.0",
|
|
31
|
+
"deepmerge": "^4.2.2",
|
|
32
|
+
"esbuild": "npm:@ohos-ports/esbuild@0.28.1-beta.2",
|
|
33
|
+
"express": "^4.17.1",
|
|
34
|
+
"fs-extra": "^8.1.0",
|
|
35
|
+
"globby": "^11.0.2",
|
|
36
|
+
"http-proxy": "^1.18.1",
|
|
37
|
+
"lodash.clonedeep": "^4.5.0",
|
|
38
|
+
"lru-cache": "^6.0.0",
|
|
39
|
+
"mime-types": "^2.1.35",
|
|
40
|
+
"node-fetch": "^2.6.1",
|
|
41
|
+
"path-to-regexp": "^6.2.0",
|
|
42
|
+
"pino": "^6.13.3",
|
|
43
|
+
"qs": "^6.10.1",
|
|
44
|
+
"resolve-package-path": "^4.0.3",
|
|
45
|
+
"semver": "^7.3.5",
|
|
46
|
+
"shelljs": "^0.8.5",
|
|
47
|
+
"slash": "^3.0.0",
|
|
48
|
+
"tcp-port-used": "^1.0.2",
|
|
49
|
+
"ts-loader": "^8.2.0",
|
|
50
|
+
"unixify": "^1.0.0",
|
|
51
|
+
"uuid": "^8.3.2"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"directory": "dist"
|
|
55
|
+
},
|
|
56
|
+
"watch": {
|
|
57
|
+
"push-build": {
|
|
58
|
+
"patterns": [
|
|
59
|
+
"src",
|
|
60
|
+
"bin",
|
|
61
|
+
"serverless.yml",
|
|
62
|
+
"default-app",
|
|
63
|
+
"package.json"
|
|
64
|
+
],
|
|
65
|
+
"extensions": [
|
|
66
|
+
"js",
|
|
67
|
+
"ts"
|
|
68
|
+
],
|
|
69
|
+
"quiet": false
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"jest": {
|
|
73
|
+
"clearMocks": true,
|
|
74
|
+
"collectCoverage": true,
|
|
75
|
+
"transform": {
|
|
76
|
+
"^.+\\.(js)?$": "babel-jest",
|
|
77
|
+
"^.+\\.ts$": "ts-jest"
|
|
78
|
+
},
|
|
79
|
+
"moduleFileExtensions": [
|
|
80
|
+
"ts",
|
|
81
|
+
"js",
|
|
82
|
+
"json"
|
|
83
|
+
],
|
|
84
|
+
"setupFilesAfterEnv": [
|
|
85
|
+
"<rootDir>/test/jest.js"
|
|
86
|
+
],
|
|
87
|
+
"transformIgnorePatterns": [
|
|
88
|
+
"<rootDir>/node_modules/"
|
|
89
|
+
],
|
|
90
|
+
"moduleNameMapper": {
|
|
91
|
+
"../package.json": "<rootDir>/package.json",
|
|
92
|
+
"^@layer0/core(.*)$": "<rootDir>/src/$1"
|
|
93
|
+
},
|
|
94
|
+
"collectCoverageFrom": [
|
|
95
|
+
"./src/**/*.{ts,js}",
|
|
96
|
+
"!**/mocks/**",
|
|
97
|
+
"!**/test-utils/**",
|
|
98
|
+
"!**/index.ts",
|
|
99
|
+
"!**/src/types.ts",
|
|
100
|
+
"!**/plugins/PluginBase.ts",
|
|
101
|
+
"!**/bin/**/*"
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
"devDependencies": {
|
|
105
|
+
"@types/cls-hooked": "^4.3.1",
|
|
106
|
+
"@types/content-type": "^1.1.3",
|
|
107
|
+
"@types/cookie": "^0.3.3",
|
|
108
|
+
"@types/cross-spawn": "^6.0.2",
|
|
109
|
+
"@types/decode-uri-component": "^0.2.0",
|
|
110
|
+
"@types/express": "^4.17.7",
|
|
111
|
+
"@types/fs-extra": "^8.1.1",
|
|
112
|
+
"@types/http-proxy": "^1.17.4",
|
|
113
|
+
"@types/jest": "^26.0.23",
|
|
114
|
+
"@types/lodash": "^4.14.162",
|
|
115
|
+
"@types/lru-cache": "^5.1.0",
|
|
116
|
+
"@types/mime-types": "^2.1.0",
|
|
117
|
+
"@types/node": "^14.6.4",
|
|
118
|
+
"@types/route-parser": "^0.1.3",
|
|
119
|
+
"@types/semver": "^7.3.9",
|
|
120
|
+
"@types/shelljs": "^0.8.8",
|
|
121
|
+
"@types/tcp-port-used": "^1.0.0",
|
|
122
|
+
"@types/unixify": "^1.0.0",
|
|
123
|
+
"@types/uuid": "^8.0.1",
|
|
124
|
+
"@types/webpack-bundle-analyzer": "^3.9.0",
|
|
125
|
+
"lodash": "^4.17.21",
|
|
126
|
+
"nock": "^13.2.8",
|
|
127
|
+
"stripe": "^9.12.0",
|
|
128
|
+
"webpack": "^5.27.0",
|
|
129
|
+
"webpack-bundle-analyzer": "^3.9.0",
|
|
130
|
+
"webpack-dev-middleware": "^4.1.0"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import RouteCriteria from '../router/RouteCriteria';
|
|
2
|
+
interface RouteInfo {
|
|
3
|
+
criteria: RouteCriteria;
|
|
4
|
+
line: number;
|
|
5
|
+
column: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Parses and introspects the user's routes file.
|
|
9
|
+
* @private
|
|
10
|
+
* @param routerFile
|
|
11
|
+
*/
|
|
12
|
+
export default function parseRouter(routerFile: string): RouteInfo[];
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
8
|
+
const parser_1 = require("@babel/parser");
|
|
9
|
+
const routeFunctions = new Set(['get', 'put', 'post', 'patch', 'options', 'delete', 'match']);
|
|
10
|
+
/**
|
|
11
|
+
* Parses and introspects the user's routes file.
|
|
12
|
+
* @private
|
|
13
|
+
* @param routerFile
|
|
14
|
+
*/
|
|
15
|
+
function parseRouter(routerFile) {
|
|
16
|
+
const code = fs_1.readFileSync(routerFile, 'utf8');
|
|
17
|
+
const ast = parser_1.parse(code, { sourceType: 'module', plugins: ['typescript'] });
|
|
18
|
+
const results = [];
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
traverse_1.default(ast, {
|
|
21
|
+
CallExpression: (path) => {
|
|
22
|
+
const call = path.node;
|
|
23
|
+
const member = call.callee;
|
|
24
|
+
const args = call.arguments;
|
|
25
|
+
if (member.type !== 'MemberExpression' || member.property.type !== 'Identifier') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const method = member.property;
|
|
29
|
+
if (routeFunctions.has(method.name)) {
|
|
30
|
+
// istanbul ignore if
|
|
31
|
+
if (!method.loc) {
|
|
32
|
+
// istanbul ignore next
|
|
33
|
+
throw new Error('Source location not available');
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
results.push({
|
|
37
|
+
criteria: getRouteCriteria(method.name, args[0], code),
|
|
38
|
+
line: method.loc.start.line,
|
|
39
|
+
column: method.loc.start.column,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
// will get here if the method's first argument is an unexpected type, which likely
|
|
44
|
+
// means this wasn't a method call on the router
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return results;
|
|
50
|
+
}
|
|
51
|
+
exports.default = parseRouter;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the criteria for the given route
|
|
54
|
+
* @param method
|
|
55
|
+
* @param criteriaNode
|
|
56
|
+
* @param code
|
|
57
|
+
*/
|
|
58
|
+
function getRouteCriteria(method, criteriaNode, code) {
|
|
59
|
+
// istanbul ignore if
|
|
60
|
+
if (!criteriaNode.start || !criteriaNode.end) {
|
|
61
|
+
// istanbul ignore next
|
|
62
|
+
throw new Error('Source location not available');
|
|
63
|
+
}
|
|
64
|
+
const snippet = code.slice(criteriaNode.start, criteriaNode.end);
|
|
65
|
+
let criteriaOrPath, criteria;
|
|
66
|
+
eval(`criteriaOrPath = ${snippet}`);
|
|
67
|
+
if (typeof criteriaOrPath === 'string') {
|
|
68
|
+
criteria = {
|
|
69
|
+
method,
|
|
70
|
+
path: criteriaOrPath,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
criteria = criteriaOrPath;
|
|
75
|
+
}
|
|
76
|
+
return criteria;
|
|
77
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Request from '../router/Request';
|
|
2
|
+
import { Router } from '../router';
|
|
3
|
+
/**
|
|
4
|
+
* Base class for a router plugin.
|
|
5
|
+
*/
|
|
6
|
+
export default class PluginBase {
|
|
7
|
+
type?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Called when plugin is registered
|
|
10
|
+
* @param router The router object to which the plugin was added.
|
|
11
|
+
*/
|
|
12
|
+
onRegister(router: Router): void;
|
|
13
|
+
/**
|
|
14
|
+
* Called when `router.run` receives a request.
|
|
15
|
+
* @param req The request object
|
|
16
|
+
*/
|
|
17
|
+
onRequest(req: Request): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable no-unused-vars */
|
|
4
|
+
/**
|
|
5
|
+
* Base class for a router plugin.
|
|
6
|
+
*/
|
|
7
|
+
class PluginBase {
|
|
8
|
+
/**
|
|
9
|
+
* Called when plugin is registered
|
|
10
|
+
* @param router The router object to which the plugin was added.
|
|
11
|
+
*/
|
|
12
|
+
onRegister(router) { }
|
|
13
|
+
/**
|
|
14
|
+
* Called when `router.run` receives a request.
|
|
15
|
+
* @param req The request object
|
|
16
|
+
*/
|
|
17
|
+
onRequest(req) { }
|
|
18
|
+
}
|
|
19
|
+
exports.default = PluginBase;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import BackendConfig from './BackendOptions';
|
|
2
|
+
import Request from './Request';
|
|
3
|
+
import Response from './Response';
|
|
4
|
+
/**
|
|
5
|
+
* @private
|
|
6
|
+
*/
|
|
7
|
+
export interface FetchOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The URL path to fetch
|
|
10
|
+
*/
|
|
11
|
+
path?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The HTTP request headers to send
|
|
14
|
+
*/
|
|
15
|
+
headers?: Headers;
|
|
16
|
+
/**
|
|
17
|
+
* If set to `true`, invalid TLS certs will be ignored. Otherwise an error will be thrown
|
|
18
|
+
* when the server returns an invalid TLS certificate.
|
|
19
|
+
*/
|
|
20
|
+
disableCheckCert?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Removes the "=" from search parameters that have no value. So for example:
|
|
23
|
+
* "http://domain.com?foo=&bar=" becomes "http://domain.com?foo&bar"
|
|
24
|
+
*/
|
|
25
|
+
removeEmptySearchParamValues?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
export default class Backend {
|
|
31
|
+
protected config: BackendConfig;
|
|
32
|
+
static setImpl(implementation: {
|
|
33
|
+
new (config: BackendConfig): Backend;
|
|
34
|
+
}): void;
|
|
35
|
+
static create(config: BackendConfig): Backend;
|
|
36
|
+
constructor(config: BackendConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Sends a request using the proxy.
|
|
39
|
+
* @param req The request being sent.
|
|
40
|
+
* @param res The response for the request.
|
|
41
|
+
*/
|
|
42
|
+
fetch(req: Request, res: Response, options: FetchOptions): Promise<unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Returns proxy configuration for http-proxy
|
|
45
|
+
* @returns proxy target url
|
|
46
|
+
*/
|
|
47
|
+
private getProxyTarget;
|
|
48
|
+
/**
|
|
49
|
+
* Returns true if the URL points to the local JS backend, otherwise false.
|
|
50
|
+
* @param url
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
private isLocal;
|
|
54
|
+
/**
|
|
55
|
+
* Returns proxy configuration object for node-fetch
|
|
56
|
+
* @param url
|
|
57
|
+
* @param req
|
|
58
|
+
* @param headers Additional request headers to include
|
|
59
|
+
* @param removeEmptySearchParamValues If true, search param values that are empty are removed so "?foo=" becomes "?foo".
|
|
60
|
+
*/
|
|
61
|
+
private getProxyRequestOptions;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
declare type Headers = {
|
|
67
|
+
[key: string]: string;
|
|
68
|
+
};
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const url_1 = require("url");
|
|
7
|
+
const https_1 = __importDefault(require("https"));
|
|
8
|
+
const http_1 = __importDefault(require("http"));
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const BackendFetchError_1 = __importDefault(require("../errors/BackendFetchError"));
|
|
11
|
+
const mergeQueryString_1 = __importDefault(require("./mergeQueryString"));
|
|
12
|
+
const constants_1 = require("../constants");
|
|
13
|
+
/**
|
|
14
|
+
* Array of response headers that will not be passed over directly from the proxied resource
|
|
15
|
+
*
|
|
16
|
+
* Notes:
|
|
17
|
+
* - transfer-encoding: as it poisons the response which will be formed
|
|
18
|
+
* based on its own transfer-encoding rather than the one received from the Lambda.
|
|
19
|
+
*
|
|
20
|
+
* - content-length: as the actual constant may be changed by buffer proxy
|
|
21
|
+
* (e.g. on moov_debug=true)
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
const IGNORE_RESPONSE_HEADERS = ['transfer-encoding', 'content-length'];
|
|
25
|
+
/**
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
class Backend {
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this.config = config;
|
|
31
|
+
}
|
|
32
|
+
static setImpl(implementation) {
|
|
33
|
+
impl = implementation;
|
|
34
|
+
}
|
|
35
|
+
static create(config) {
|
|
36
|
+
return new impl(config);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Sends a request using the proxy.
|
|
40
|
+
* @param req The request being sent.
|
|
41
|
+
* @param res The response for the request.
|
|
42
|
+
*/
|
|
43
|
+
async fetch(req, res, options) {
|
|
44
|
+
const { path, headers } = options || {};
|
|
45
|
+
// Create url for proxy with query params added if existing
|
|
46
|
+
const url = this.getProxyTarget(req, path);
|
|
47
|
+
const requestOptions = this.getProxyRequestOptions(url, req, headers, options === null || options === void 0 ? void 0 : options.removeEmptySearchParamValues);
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const lib = url.protocol === 'https:' ? https_1.default : http_1.default;
|
|
50
|
+
const upstreamReq = lib.request(requestOptions, upstreamRes => {
|
|
51
|
+
let buf = [];
|
|
52
|
+
upstreamRes
|
|
53
|
+
.on('data', (chunk) => buf.push(chunk))
|
|
54
|
+
.on('end', () => {
|
|
55
|
+
/* istanbul ignore else */
|
|
56
|
+
if (upstreamRes.complete) {
|
|
57
|
+
Object.entries(upstreamRes.headers)
|
|
58
|
+
.filter(([name]) => !IGNORE_RESPONSE_HEADERS.includes(name.toLowerCase()))
|
|
59
|
+
.forEach(([name, value]) => {
|
|
60
|
+
try {
|
|
61
|
+
res.setHeader(name, value);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
console.warn(`Could not relay upstream response header ${name} with value ${value}`, e);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
res.statusCode = upstreamRes.statusCode;
|
|
68
|
+
res.statusMessage = upstreamRes.statusMessage;
|
|
69
|
+
res.body = Buffer.concat(buf);
|
|
70
|
+
/* istanbul ignore if */
|
|
71
|
+
if (process.env.DEBUG === 'true') {
|
|
72
|
+
console.log('proxy', `[${res.statusCode} ${res.statusMessage}]`, url);
|
|
73
|
+
}
|
|
74
|
+
resolve(undefined);
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
.on('error',
|
|
78
|
+
/* istanbul ignore next */ e => {
|
|
79
|
+
reject(new BackendFetchError_1.default(e));
|
|
80
|
+
})
|
|
81
|
+
// Closing the connection before the response is complete
|
|
82
|
+
// has different behaviours depending on NodeJs version
|
|
83
|
+
// - node 12: triggers a 'close' event on the Request and Response, and an 'end' event on Response in between
|
|
84
|
+
// - node 14: triggers a 'close' event on the Request and Response, but no 'end' event on Response anymore
|
|
85
|
+
// - node 16: triggers a 'close' event on the Request and Response and an "aborted" error on Response in between
|
|
86
|
+
// See playground at https://runkit.com/adrien-k/aborted-res-error
|
|
87
|
+
//
|
|
88
|
+
// We take the most compatible approach, although in v16 and above this should be caught by the 'error' event.
|
|
89
|
+
/* istanbul ignore next */
|
|
90
|
+
.on('close',
|
|
91
|
+
/* istanbul ignore next */ () => {
|
|
92
|
+
if (!upstreamRes.complete) {
|
|
93
|
+
reject(new BackendFetchError_1.default(new Error('The connection was terminated while the message was still being sent')));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
upstreamReq.on('error', e => reject(new BackendFetchError_1.default(e)));
|
|
98
|
+
upstreamReq.end(req.rawBody);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns proxy configuration for http-proxy
|
|
103
|
+
* @returns proxy target url
|
|
104
|
+
*/
|
|
105
|
+
getProxyTarget(req, path) {
|
|
106
|
+
let url = path ? mergeQueryString_1.default(req.url, path) : req.url;
|
|
107
|
+
const { domainOrIp, basePath, port } = this.config;
|
|
108
|
+
if (basePath) {
|
|
109
|
+
url = path_1.join(basePath, url);
|
|
110
|
+
}
|
|
111
|
+
/* istanbul ignore next */
|
|
112
|
+
if (domainOrIp) {
|
|
113
|
+
const protocol = domainOrIp.match(/^(127.0.0.1|localhost)(:\d+)?$/) ? 'http' : 'https';
|
|
114
|
+
const domain = `${domainOrIp}${port ? `:${port}` : ''}`;
|
|
115
|
+
url = `${protocol}://${path_1.join(domain, url)}`;
|
|
116
|
+
}
|
|
117
|
+
const parsed = url_1.parse(url, true);
|
|
118
|
+
// Force insecure protocol if header is present
|
|
119
|
+
if (req.getHeader(constants_1.HTTP_HEADERS.x0Protocol) === 'http') {
|
|
120
|
+
parsed.protocol = 'http:';
|
|
121
|
+
}
|
|
122
|
+
return parsed;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns true if the URL points to the local JS backend, otherwise false.
|
|
126
|
+
* @param url
|
|
127
|
+
* @returns
|
|
128
|
+
*/
|
|
129
|
+
isLocal(url) {
|
|
130
|
+
return url.hostname === constants_1.JS_BACKEND_HOSTNAME;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns proxy configuration object for node-fetch
|
|
134
|
+
* @param url
|
|
135
|
+
* @param req
|
|
136
|
+
* @param headers Additional request headers to include
|
|
137
|
+
* @param removeEmptySearchParamValues If true, search param values that are empty are removed so "?foo=" becomes "?foo".
|
|
138
|
+
*/
|
|
139
|
+
getProxyRequestOptions(url, req, headers, removeEmptySearchParamValues) {
|
|
140
|
+
let agent = null;
|
|
141
|
+
if (this.config.disableCheckCert && url.protocol === 'https:') {
|
|
142
|
+
// For self signed cert fix on local development S3 bucket
|
|
143
|
+
agent = new https_1.default.Agent({ rejectUnauthorized: false });
|
|
144
|
+
}
|
|
145
|
+
const upstreamHeaders = {
|
|
146
|
+
...req.headers,
|
|
147
|
+
...headers,
|
|
148
|
+
host: this.config.hostHeader || req.headers.host,
|
|
149
|
+
};
|
|
150
|
+
if (this.isLocal(url)) {
|
|
151
|
+
// Some libraries, like [is-https](https://github.com/unjs/is-https#behaviour), rely on x-forwarded-proto
|
|
152
|
+
// to determine if the source request was made securely. This is notably used by Vue Storefront 2. Before
|
|
153
|
+
// we added this header, API requests made by Vue Storefront 2 from the cloud would attempt to reenter Layer0
|
|
154
|
+
// using an http POST, which would be redirected to an https GET, which would cause an infinite loop and soaring lambda costs.
|
|
155
|
+
// Note that we only add x-forwarded-proto for local requests, which never happen over TLS. For remote requests, TLS is used
|
|
156
|
+
// when the downstream request used TLS. We've chosen to do this in order to avoid altering the public behavior of Layer0, which
|
|
157
|
+
// has never sent x-forwarded-proto to origins.
|
|
158
|
+
upstreamHeaders['x-forwarded-proto'] = req.secure ? 'https' : 'http';
|
|
159
|
+
}
|
|
160
|
+
let path = url.path;
|
|
161
|
+
if (removeEmptySearchParamValues === true && path) {
|
|
162
|
+
path = path.replace(/=(?=&|$)/gm, '');
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
...url,
|
|
166
|
+
path,
|
|
167
|
+
method: req.method,
|
|
168
|
+
timeout: this.config.firstByteTimeout || 0,
|
|
169
|
+
agent,
|
|
170
|
+
body: req.rawBody,
|
|
171
|
+
headers: upstreamHeaders,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.default = Backend;
|
|
176
|
+
let impl = Backend;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import Request from './Request';
|
|
2
|
+
import Response from './Response';
|
|
3
|
+
import Route from './Route';
|
|
4
|
+
import { CacheOptions } from './CacheOptions';
|
|
5
|
+
import { CorsOptions, ProxyOptions, ServeStaticOptions, RedirectOptions, VerifyJwtOptions } from './ResponseWriter';
|
|
6
|
+
export interface CookieOptions {
|
|
7
|
+
Expires?: string;
|
|
8
|
+
'Max-Age'?: number;
|
|
9
|
+
Domain?: string;
|
|
10
|
+
Path?: string;
|
|
11
|
+
Secure?: boolean;
|
|
12
|
+
HttpOnly?: boolean;
|
|
13
|
+
SameSite?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
* Having a no-op BaseResponseWriter makes it easy for us to stub out the writer
|
|
18
|
+
* when introspecing the router. This is needed to implement Router.getPrefetchableRoutes
|
|
19
|
+
*/
|
|
20
|
+
export declare class BaseResponseWriter {
|
|
21
|
+
constructor(req?: Request, res?: Response, route?: Route);
|
|
22
|
+
cache(options: CacheOptions): void;
|
|
23
|
+
redirect(to: string, options: RedirectOptions): void;
|
|
24
|
+
/**
|
|
25
|
+
* Translates redirect params into normalized version that solves backward compatibility
|
|
26
|
+
* issues and also takes into account query parameters that may be included in the query
|
|
27
|
+
* string itself.
|
|
28
|
+
*
|
|
29
|
+
* @param to string to where we are redirecting the request; may have query string
|
|
30
|
+
* @param options options with which we are redirecting the request
|
|
31
|
+
*/
|
|
32
|
+
protected _readRedirectParams(to: string, options: RedirectOptions): {
|
|
33
|
+
to: string;
|
|
34
|
+
statusCode: number;
|
|
35
|
+
query: {};
|
|
36
|
+
};
|
|
37
|
+
proxy(backend: string, options?: ProxyOptions): void;
|
|
38
|
+
render(cb: (request: Request, proxy: (backend: string, options: ProxyOptions) => void, params: any) => void): void;
|
|
39
|
+
stream(backend: string): void;
|
|
40
|
+
serveStatic(path: string, options?: ServeStaticOptions): void;
|
|
41
|
+
updatePath(destination: string): void;
|
|
42
|
+
rewrite(destination: string, pattern: string): void;
|
|
43
|
+
setRequestHeader(name: string, value: string): void;
|
|
44
|
+
updateRequestHeader(name: string, match: RegExp, replace: string): void;
|
|
45
|
+
removeRequestHeader(name: string): void;
|
|
46
|
+
setUpstreamResponseHeader(name: string, value: string): void;
|
|
47
|
+
updateUpstreamResponseHeader(name: string, match: RegExp, replace: string): void;
|
|
48
|
+
removeUpstreamResponseHeader(name: string): void;
|
|
49
|
+
verifyJwt(options: VerifyJwtOptions): void;
|
|
50
|
+
setResponseHeader(name: string, value: string): void;
|
|
51
|
+
updateResponseHeader(name: string, match: RegExp, replace: string): void;
|
|
52
|
+
removeResponseHeader(name: string): void;
|
|
53
|
+
addResponseCookie(name: string, value: string, options?: CookieOptions): void;
|
|
54
|
+
updateResponseCookie(name: string, match: RegExp, replace: string): void;
|
|
55
|
+
removeResponseCookie(name: string): void;
|
|
56
|
+
addUpstreamResponseCookie(name: string, value: string, options?: CookieOptions): void;
|
|
57
|
+
updateUpstreamResponseCookie(name: string, match: RegExp, replace: string): void;
|
|
58
|
+
removeUpstreamResponseCookie(name: string): void;
|
|
59
|
+
send(content: string | (() => string), statusCode: number, statusMessage?: string): void;
|
|
60
|
+
compute(callback: (request: Request, response: Response) => void | Promise<void>): void;
|
|
61
|
+
serviceWorker(path: string): void;
|
|
62
|
+
allowCors(options: CorsOptions): void;
|
|
63
|
+
appShell(indexHtmlPath: string): void;
|
|
64
|
+
renderWithApp(options?: ProxyOptions): void;
|
|
65
|
+
}
|