@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,284 @@
|
|
|
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 config_1 = __importDefault(require("../config"));
|
|
7
|
+
const toEdgeRegex_1 = __importDefault(require("../utils/toEdgeRegex"));
|
|
8
|
+
const toHttpMethodMatchRegex_1 = __importDefault(require("../utils/toHttpMethodMatchRegex"));
|
|
9
|
+
const convertStringMatcherToRegex_1 = __importDefault(require("../utils/convertStringMatcherToRegex"));
|
|
10
|
+
const EdgeResponseWriter_1 = __importDefault(require("./EdgeResponseWriter"));
|
|
11
|
+
const constants_1 = require("../constants");
|
|
12
|
+
const RequestContext_1 = __importDefault(require("../router/RequestContext"));
|
|
13
|
+
const universalRouteUtils_1 = require("../router/universalRouteUtils");
|
|
14
|
+
const EdgeErrorPageResponseWriter_1 = __importDefault(require("./EdgeErrorPageResponseWriter"));
|
|
15
|
+
/**
|
|
16
|
+
* Returns cache object
|
|
17
|
+
*
|
|
18
|
+
* Notes:
|
|
19
|
+
* - Method caching is only allowed when it's explicit:
|
|
20
|
+
* 1. The matching was explicitly done on `post` and other methods and
|
|
21
|
+
* 2. The caching properties were defined on the same route.
|
|
22
|
+
*
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
function buildRouteCacheKeysFromEdgeWriter({ edgeConfig }, matchExplicitMethod) {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
// istanbul ignore next - edgeConfig.cache?.maxAgeSeconds is apparently untestable as it always shows as uncovered
|
|
28
|
+
if (edgeConfig.cache && ((_a = edgeConfig.cache) === null || _a === void 0 ? void 0 : _a.maxAgeSeconds) &&
|
|
29
|
+
((_b = edgeConfig.cache) === null || _b === void 0 ? void 0 : _b.maxAgeSeconds) > 0 &&
|
|
30
|
+
matchExplicitMethod) {
|
|
31
|
+
return {
|
|
32
|
+
...edgeConfig.cache,
|
|
33
|
+
matchExplicitMethod,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return edgeConfig.cache;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns route action
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
function buildRouteActionFromEdgeWriter({ edgeConfig }, isErrorRoute) {
|
|
43
|
+
var _a;
|
|
44
|
+
const route = edgeConfig.route;
|
|
45
|
+
// On error routes we don't use the default statusCode since we must preserve the status code
|
|
46
|
+
// of the error route.
|
|
47
|
+
if (((_a = edgeConfig.route) === null || _a === void 0 ? void 0 : _a.action) === constants_1.ACTIONS.syntheticRes &&
|
|
48
|
+
!edgeConfig.route.statusCode &&
|
|
49
|
+
!isErrorRoute) {
|
|
50
|
+
edgeConfig.route.statusCode = 200;
|
|
51
|
+
}
|
|
52
|
+
return route;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns transformation object
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
function buildTransformFromEdgeWriter({ edgeConfig }) {
|
|
59
|
+
return edgeConfig.transform;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns the jwtVerification object (if any) validation is performed earlier
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
function buildVerifyJwtFromEdgeWriter({ edgeConfig, }) {
|
|
66
|
+
return edgeConfig.jwtVerification;
|
|
67
|
+
}
|
|
68
|
+
function transformBodyCriteria(obj) {
|
|
69
|
+
return Object.entries(obj).reduce((memo, [key, value]) => {
|
|
70
|
+
if (value instanceof RegExp) {
|
|
71
|
+
memo[key] = convertStringMatcherToRegex_1.default(value);
|
|
72
|
+
}
|
|
73
|
+
else if (typeof value === 'object' && value !== null) {
|
|
74
|
+
memo[key] = transformBodyCriteria(value);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
memo[key] = convertStringMatcherToRegex_1.default(value);
|
|
78
|
+
}
|
|
79
|
+
return memo;
|
|
80
|
+
}, {});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Build Outer Edge match configuration
|
|
84
|
+
*
|
|
85
|
+
* Notes:
|
|
86
|
+
* - When resulting array is empty, it means that all requests should match
|
|
87
|
+
* - If method matching is set to explicit method then set it in `matchExplicitMethod`
|
|
88
|
+
* - All routes have implicit https protocol, so only if a criteria has explicitly been
|
|
89
|
+
* set to http do we match for that protocol, otherwise we match https.
|
|
90
|
+
*
|
|
91
|
+
* @param route
|
|
92
|
+
* @returns An array of match criteria
|
|
93
|
+
* @private
|
|
94
|
+
*/
|
|
95
|
+
function buildMatcherFromRoute(route) {
|
|
96
|
+
var _a;
|
|
97
|
+
const match = [];
|
|
98
|
+
const matchResp = [];
|
|
99
|
+
let matchProtocolJavaScriptRegExpSource;
|
|
100
|
+
let matchExplicitMethod;
|
|
101
|
+
if (route.criteria.protocol) {
|
|
102
|
+
let regex;
|
|
103
|
+
// Because HTTP is a subset of HTTPS we make sure that when strings are used we match
|
|
104
|
+
// the whole value rather than just a part of it.
|
|
105
|
+
if (typeof route.criteria.protocol === 'string') {
|
|
106
|
+
regex = new RegExp(`^${route.criteria.protocol}$`, 'i');
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
regex = new RegExp(route.criteria.protocol);
|
|
110
|
+
}
|
|
111
|
+
if (!regex.test('http') && !regex.test('https')) {
|
|
112
|
+
throw new Error('Protocol matcher must match either "http" or "https"');
|
|
113
|
+
}
|
|
114
|
+
matchProtocolJavaScriptRegExpSource = regex.source;
|
|
115
|
+
}
|
|
116
|
+
if (route.criteria.path) {
|
|
117
|
+
match.push({
|
|
118
|
+
value: '${path}',
|
|
119
|
+
matchRegex: route.toEdgeRegexString(),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (route.criteria.method) {
|
|
123
|
+
let matchRegex;
|
|
124
|
+
if (typeof route.criteria.method !== 'string') {
|
|
125
|
+
matchRegex = route.criteria.method;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
matchRegex = toHttpMethodMatchRegex_1.default(route.criteria.method);
|
|
129
|
+
if (Object.values(constants_1.HTTP_METHODS).includes(route.criteria.method)) {
|
|
130
|
+
matchExplicitMethod = route.criteria.method;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
match.push({
|
|
134
|
+
value: '${method}',
|
|
135
|
+
matchRegex: toEdgeRegex_1.default(matchRegex),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (route.criteria.headers) {
|
|
139
|
+
Object.entries(route.criteria.headers).forEach(([name, value]) => {
|
|
140
|
+
match.push({
|
|
141
|
+
value: `\${req:${name}}`,
|
|
142
|
+
matchRegex: convertStringMatcherToRegex_1.default(value),
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
// Match is executed on deliver phase. This is required for error pages.
|
|
147
|
+
if ((_a = route.criteria.response) === null || _a === void 0 ? void 0 : _a.statusCode) {
|
|
148
|
+
matchResp.push({
|
|
149
|
+
value: `\${res:status}`,
|
|
150
|
+
matchRegex: toEdgeRegex_1.default(route.criteria.response.statusCode),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (route.criteria.query) {
|
|
154
|
+
Object.entries(route.criteria.query).forEach(([name, value]) => {
|
|
155
|
+
// Dynamic query matcher (ex: { query: { id: ':id' } }) don't need to be
|
|
156
|
+
// strictly matched against the route. They can be present or not.
|
|
157
|
+
if (universalRouteUtils_1.isParamMatcher(value))
|
|
158
|
+
return;
|
|
159
|
+
match.push({
|
|
160
|
+
value: `\${query:${name}}`,
|
|
161
|
+
matchRegex: convertStringMatcherToRegex_1.default(value),
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (route.criteria.cookies) {
|
|
166
|
+
Object.entries(route.criteria.cookies).forEach(([name, value]) => {
|
|
167
|
+
match.push({
|
|
168
|
+
value: `\${req:cookie:${name}}`,
|
|
169
|
+
matchRegex: convertStringMatcherToRegex_1.default(value),
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (route.criteria.body) {
|
|
174
|
+
match.push({
|
|
175
|
+
matchBody: JSON.stringify({
|
|
176
|
+
parse: route.criteria.body.parse,
|
|
177
|
+
criteria: transformBodyCriteria(route.criteria.body.criteria),
|
|
178
|
+
}),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
match,
|
|
183
|
+
matchResp,
|
|
184
|
+
matchExplicitMethod,
|
|
185
|
+
matchProtocolJavaScriptRegExpSource,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Creates an outer edge manager config for the specified router by iterating through
|
|
190
|
+
* each route and calling it with a mock request
|
|
191
|
+
* and response.
|
|
192
|
+
* @param router
|
|
193
|
+
* @return An object containing the Edge config
|
|
194
|
+
*/
|
|
195
|
+
async function createEdgeConfig(router) {
|
|
196
|
+
let destinations = {};
|
|
197
|
+
if (!Object.keys(router.getDestinations()).length) {
|
|
198
|
+
destinations = {
|
|
199
|
+
default: await createDestination(router),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
for (let d in router.getDestinations()) {
|
|
204
|
+
destinations[d] = await createDestination(router.getDestinations()[d]);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
version: getLayer0Version(),
|
|
209
|
+
backends: {
|
|
210
|
+
...config_1.default.get('backends'),
|
|
211
|
+
},
|
|
212
|
+
destinations,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
exports.default = createEdgeConfig;
|
|
216
|
+
/**
|
|
217
|
+
* Gets the version of @layer0/core. For this to work in testing an entry needed
|
|
218
|
+
* to be added to moduleNameMapper in the jest config specifically for package.json
|
|
219
|
+
* @return {String}
|
|
220
|
+
*/
|
|
221
|
+
function getLayer0Version() {
|
|
222
|
+
// We purposefully don't override this version so that we can see in edge
|
|
223
|
+
// responses the *exact* version with which the edge was built.
|
|
224
|
+
return require('../package.json').version;
|
|
225
|
+
}
|
|
226
|
+
async function createDestinationMapFunction(route, writer, faultyRoutes, isErrorRoute) {
|
|
227
|
+
try {
|
|
228
|
+
// @ts-ignore
|
|
229
|
+
await route.handler(writer);
|
|
230
|
+
}
|
|
231
|
+
catch (e) {
|
|
232
|
+
Error.captureStackTrace(e);
|
|
233
|
+
faultyRoutes.push({
|
|
234
|
+
route: route.toString(),
|
|
235
|
+
stackTrace: e.stack,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
const { match, matchResp, matchExplicitMethod, matchProtocolJavaScriptRegExpSource } = buildMatcherFromRoute(route);
|
|
239
|
+
return {
|
|
240
|
+
// used when building .layer0 to assemble the s3 directory structure
|
|
241
|
+
path: route.criteria.path,
|
|
242
|
+
// Consumed by Cache metrics to build the route string
|
|
243
|
+
routeJson: route.toJson(),
|
|
244
|
+
match,
|
|
245
|
+
matchResp,
|
|
246
|
+
matchProtocolJavaScriptRegExpSource,
|
|
247
|
+
cache: buildRouteCacheKeysFromEdgeWriter(writer, matchExplicitMethod),
|
|
248
|
+
route: buildRouteActionFromEdgeWriter(writer, isErrorRoute),
|
|
249
|
+
transform: buildTransformFromEdgeWriter(writer),
|
|
250
|
+
jwtVerification: buildVerifyJwtFromEdgeWriter(writer),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
async function createDestination(router) {
|
|
254
|
+
const faultyRoutes = [];
|
|
255
|
+
const destination = {
|
|
256
|
+
index: router.index,
|
|
257
|
+
errorRoutes: await Promise.all(router
|
|
258
|
+
.getRouteGroups()
|
|
259
|
+
.getRoutes()
|
|
260
|
+
.filter(route => route.isRespRoute())
|
|
261
|
+
.map(route => createDestinationMapFunction(route, new EdgeErrorPageResponseWriter_1.default({
|
|
262
|
+
url: '',
|
|
263
|
+
headers: {},
|
|
264
|
+
}, {}, route, new RequestContext_1.default()), faultyRoutes, true))),
|
|
265
|
+
routes: await Promise.all(router
|
|
266
|
+
.getRouteGroups()
|
|
267
|
+
.getRoutes()
|
|
268
|
+
.filter(route => !route.isRespRoute())
|
|
269
|
+
.map(route => createDestinationMapFunction(route, new EdgeResponseWriter_1.default({
|
|
270
|
+
url: '',
|
|
271
|
+
headers: {},
|
|
272
|
+
}, {}, route, new RequestContext_1.default()), faultyRoutes, false))),
|
|
273
|
+
};
|
|
274
|
+
// If any faulty routes occured, throw error with all faulty routes listed
|
|
275
|
+
if (faultyRoutes.length) {
|
|
276
|
+
let errorMessage = '\nErrors occurred while attempting to deploy your application to Layer0 edge.' +
|
|
277
|
+
`\nThe following ${faultyRoutes.length > 1 ? 'routes' : 'route'} could not be processed:`;
|
|
278
|
+
faultyRoutes.forEach(({ route, stackTrace }) => {
|
|
279
|
+
errorMessage = errorMessage.concat(`\n* ${route}: ${stackTrace}`);
|
|
280
|
+
});
|
|
281
|
+
throw new Error(errorMessage);
|
|
282
|
+
}
|
|
283
|
+
return destination;
|
|
284
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Used to determine if the app is running in the cloud.
|
|
3
|
+
* @returns `true` when running in the cloud, `false` otherwise
|
|
4
|
+
*/
|
|
5
|
+
export declare function isCloud(): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Returns true when running locally, either in dev or production mode
|
|
8
|
+
*/
|
|
9
|
+
export declare function isLocal(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Used to determine if the app is running on a production build.
|
|
12
|
+
* @returns `true` when running a production build, either locally or in the cloud; `false` otherwise
|
|
13
|
+
*/
|
|
14
|
+
export declare function isProductionBuild(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Used to determine if the app is running in `layer0 run` development environment
|
|
17
|
+
* @returns `true` when running with `layer0 run`without production flag, `false` otherwise
|
|
18
|
+
*/
|
|
19
|
+
export declare function isLayer0RunDev(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Determines whether or not we are running in a browser
|
|
22
|
+
* @returns `true` when running in a browser, otherwise false
|
|
23
|
+
*/
|
|
24
|
+
export declare function isBrowser(): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("./constants");
|
|
4
|
+
/**
|
|
5
|
+
* Used to determine if the app is running in the cloud.
|
|
6
|
+
* @returns `true` when running in the cloud, `false` otherwise
|
|
7
|
+
*/
|
|
8
|
+
function isCloud() {
|
|
9
|
+
return process.env[constants_1.LAYER0_ENV_VARIABLES.deploymentType] === constants_1.LAYER0_DEPLOYMENT_TYPE_AWS;
|
|
10
|
+
}
|
|
11
|
+
exports.isCloud = isCloud;
|
|
12
|
+
/**
|
|
13
|
+
* Returns true when running locally, either in dev or production mode
|
|
14
|
+
*/
|
|
15
|
+
function isLocal() {
|
|
16
|
+
return process.env.LAYER0_LOCAL === 'true';
|
|
17
|
+
}
|
|
18
|
+
exports.isLocal = isLocal;
|
|
19
|
+
/**
|
|
20
|
+
* Used to determine if the app is running on a production build.
|
|
21
|
+
* @returns `true` when running a production build, either locally or in the cloud; `false` otherwise
|
|
22
|
+
*/
|
|
23
|
+
function isProductionBuild() {
|
|
24
|
+
return process.env.NODE_ENV === 'production';
|
|
25
|
+
}
|
|
26
|
+
exports.isProductionBuild = isProductionBuild;
|
|
27
|
+
/**
|
|
28
|
+
* Used to determine if the app is running in `layer0 run` development environment
|
|
29
|
+
* @returns `true` when running with `layer0 run`without production flag, `false` otherwise
|
|
30
|
+
*/
|
|
31
|
+
function isLayer0RunDev() {
|
|
32
|
+
return !isCloud() && !isProductionBuild();
|
|
33
|
+
}
|
|
34
|
+
exports.isLayer0RunDev = isLayer0RunDev;
|
|
35
|
+
/**
|
|
36
|
+
* Determines whether or not we are running in a browser
|
|
37
|
+
* @returns `true` when running in a browser, otherwise false
|
|
38
|
+
*/
|
|
39
|
+
function isBrowser() {
|
|
40
|
+
return typeof window !== 'undefined';
|
|
41
|
+
}
|
|
42
|
+
exports.isBrowser = isBrowser;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* To be thrown when failing to connect to a backend.
|
|
3
|
+
*/
|
|
4
|
+
export default class BackendFetchError extends Error {
|
|
5
|
+
readonly cause: Error;
|
|
6
|
+
readonly type = "BackendFetchError";
|
|
7
|
+
/**
|
|
8
|
+
* @param cause The root error emitted by http/https.request
|
|
9
|
+
*/
|
|
10
|
+
constructor(cause: Error);
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* istanbul ignore file - For some reason the constructor can't get 100% coverage on the super call */
|
|
4
|
+
/**
|
|
5
|
+
* To be thrown when failing to connect to a backend.
|
|
6
|
+
*/
|
|
7
|
+
class BackendFetchError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* @param cause The root error emitted by http/https.request
|
|
10
|
+
*/
|
|
11
|
+
constructor(cause) {
|
|
12
|
+
super(cause.message);
|
|
13
|
+
this.type = 'BackendFetchError';
|
|
14
|
+
this.cause = cause;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = BackendFetchError;
|
|
@@ -0,0 +1,26 @@
|
|
|
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 v8_1 = __importDefault(require("v8"));
|
|
7
|
+
/**
|
|
8
|
+
* To be thrown when the user's application fails to build.
|
|
9
|
+
*/
|
|
10
|
+
class FrameworkBuildError extends Error {
|
|
11
|
+
constructor(framework, command, error) {
|
|
12
|
+
super(`${framework} build command "${command}" failed. This is most likely due to an error in your application code and not a problem with Layer0. Try running "${command}" on your CLI`); // istanbul ignore next - this is a known issue with TypeScript
|
|
13
|
+
this.isUserError = true;
|
|
14
|
+
if (error && error.message.includes('JavaScript heap out of memory')) {
|
|
15
|
+
const currentMemoryLimit = v8_1.default.getHeapStatistics().total_available_size;
|
|
16
|
+
const memoryInMb = (+currentMemoryLimit * 2) / (1024 * 1024);
|
|
17
|
+
this.message = `Node.js ran out of memory while attempting to build your app.
|
|
18
|
+
Currently Node processes are capped at ${currentMemoryLimit} bytes of memory.
|
|
19
|
+
You can raise this limit by setting the following environment variable in your shell initialization script:
|
|
20
|
+
|
|
21
|
+
NODE_OPTIONS=--max_old_space_size=${Math.round(memoryInMb)}
|
|
22
|
+
`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = FrameworkBuildError;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function __export(m) {
|
|
3
|
+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
4
|
+
}
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
__export(require("./router"));
|
|
7
|
+
__export(require("./constants"));
|
|
8
|
+
var config_1 = require("./config");
|
|
9
|
+
exports.config = config_1.default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merges the provided config into package.json and writes the result to disk.
|
|
3
|
+
* @param contents The config to add
|
|
4
|
+
* @param overwrite True to overwrite any values that already exist in the package.json file
|
|
5
|
+
* @return The resulting package.json contents as an object
|
|
6
|
+
*/
|
|
7
|
+
export default function addToPackageJson(contents: any, overwrite?: boolean): any;
|
|
@@ -0,0 +1,22 @@
|
|
|
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 path_1 = require("path");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
9
|
+
/**
|
|
10
|
+
* Merges the provided config into package.json and writes the result to disk.
|
|
11
|
+
* @param contents The config to add
|
|
12
|
+
* @param overwrite True to overwrite any values that already exist in the package.json file
|
|
13
|
+
* @return The resulting package.json contents as an object
|
|
14
|
+
*/
|
|
15
|
+
function addToPackageJson(contents, overwrite = true) {
|
|
16
|
+
const file = path_1.join(process.cwd(), 'package.json');
|
|
17
|
+
let packageContents = JSON.parse(fs_1.readFileSync(file, 'utf8'));
|
|
18
|
+
packageContents = overwrite ? deepmerge_1.default(packageContents, contents) : deepmerge_1.default(contents, packageContents);
|
|
19
|
+
fs_1.writeFileSync(file, JSON.stringify(packageContents, null, 2), 'utf8');
|
|
20
|
+
return packageContents;
|
|
21
|
+
}
|
|
22
|
+
exports.default = addToPackageJson;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
/* istanbul ignore file */
|
|
7
|
+
const DeploymentBuilder_1 = __importDefault(require("../deploy/DeploymentBuilder"));
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
/**
|
|
10
|
+
* Adds all required dependencies and files to the user's app by copying them
|
|
11
|
+
* over from src/default-app.
|
|
12
|
+
*/
|
|
13
|
+
function init() {
|
|
14
|
+
const builder = new DeploymentBuilder_1.default(process.cwd());
|
|
15
|
+
builder.addDefaultAppResources(path_1.join(__dirname, '..', 'default-app'));
|
|
16
|
+
}
|
|
17
|
+
exports.default = init;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class that all framework integration packages should implement to start a
|
|
3
|
+
* server instance of the framework to which requests can be proxied as the __js__ backend.
|
|
4
|
+
*/
|
|
5
|
+
export default class JSBackend {
|
|
6
|
+
protected readonly port: number;
|
|
7
|
+
private started;
|
|
8
|
+
static readonly __type__ = "JSBackend";
|
|
9
|
+
/**
|
|
10
|
+
* Returns true if the provided class extends JSBackend.
|
|
11
|
+
* @param obj A class
|
|
12
|
+
*/
|
|
13
|
+
static isSubclass(obj: any): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* @param port The port to which the server instance should bind.
|
|
16
|
+
*/
|
|
17
|
+
constructor(port: number);
|
|
18
|
+
/**
|
|
19
|
+
* Starts the app's server build. We don't start the app if the target port is already
|
|
20
|
+
* taken. This will be the case when using layer0 run --serverless to emulate the cloud locally,
|
|
21
|
+
* since serverless-offline sandboxes the app in such a way that it's difficult to keep
|
|
22
|
+
* track of whether or not the app has been started - checking the port is the easiest way -
|
|
23
|
+
* and it will attempt to start the app on every request.
|
|
24
|
+
*/
|
|
25
|
+
start(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Subclasses must override this method to implement starting the app's server build.
|
|
28
|
+
*/
|
|
29
|
+
protected doStart(): Promise<void>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 tcp_port_used_1 = __importDefault(require("tcp-port-used"));
|
|
7
|
+
let started = false;
|
|
8
|
+
/**
|
|
9
|
+
* Base class that all framework integration packages should implement to start a
|
|
10
|
+
* server instance of the framework to which requests can be proxied as the __js__ backend.
|
|
11
|
+
*/
|
|
12
|
+
class JSBackend {
|
|
13
|
+
/**
|
|
14
|
+
* @param port The port to which the server instance should bind.
|
|
15
|
+
*/
|
|
16
|
+
constructor(port) {
|
|
17
|
+
this.started = false;
|
|
18
|
+
this.port = port;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns true if the provided class extends JSBackend.
|
|
22
|
+
* @param obj A class
|
|
23
|
+
*/
|
|
24
|
+
static isSubclass(obj) {
|
|
25
|
+
return obj.__type__ == 'JSBackend';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Starts the app's server build. We don't start the app if the target port is already
|
|
29
|
+
* taken. This will be the case when using layer0 run --serverless to emulate the cloud locally,
|
|
30
|
+
* since serverless-offline sandboxes the app in such a way that it's difficult to keep
|
|
31
|
+
* track of whether or not the app has been started - checking the port is the easiest way -
|
|
32
|
+
* and it will attempt to start the app on every request.
|
|
33
|
+
*/
|
|
34
|
+
async start() {
|
|
35
|
+
if (started || (await tcp_port_used_1.default.check(this.port))) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
started = true;
|
|
40
|
+
await this.doStart();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Subclasses must override this method to implement starting the app's server build.
|
|
45
|
+
*/
|
|
46
|
+
async doStart() {
|
|
47
|
+
throw new Error('Subclasses must override the doStart method.');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.default = JSBackend;
|
|
51
|
+
JSBackend.__type__ = 'JSBackend';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import JSBackend from './JSBackend';
|
|
3
|
+
import { RequestListener } from 'http';
|
|
4
|
+
export default class RequestListenerJSBackend extends JSBackend {
|
|
5
|
+
private listener;
|
|
6
|
+
constructor(port: number, listener: RequestListener);
|
|
7
|
+
doStart(): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 JSBackend_1 = __importDefault(require("./JSBackend"));
|
|
7
|
+
const http_1 = require("http");
|
|
8
|
+
class RequestListenerJSBackend extends JSBackend_1.default {
|
|
9
|
+
constructor(port, listener) {
|
|
10
|
+
super(port);
|
|
11
|
+
this.listener = listener;
|
|
12
|
+
}
|
|
13
|
+
async doStart() {
|
|
14
|
+
return new Promise(resolve => {
|
|
15
|
+
http_1.createServer(this.listener).listen(this.port, resolve);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = RequestListenerJSBackend;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Response from '../router/Response';
|
|
2
|
+
/**
|
|
3
|
+
* Adapts the response body to the downstream accept encoding. This may mean:
|
|
4
|
+
* a) Not doing anything if the downstream accept encoding the content encoding are compatible.
|
|
5
|
+
* b) Compressing the response body to a downstream compatible encoding, if response body has no encoding.
|
|
6
|
+
* c) Decompressing the response body from downstream incompatible encoding and optionally re-compressing it
|
|
7
|
+
* to downstream compatible encoding.
|
|
8
|
+
*
|
|
9
|
+
* If any compression is done by this function, then the content-encoding and content-length headers will
|
|
10
|
+
* correspond to the new encoding/length of the response body.
|
|
11
|
+
*
|
|
12
|
+
* @param acceptEncoding Value of downstream accept-encoding header
|
|
13
|
+
* @param res HttpResponse object
|
|
14
|
+
* @param response Lambda response object
|
|
15
|
+
*/
|
|
16
|
+
declare const adaptResponseEncodingToDownstream: (acceptEncoding: string, res: Response, response: any) => void;
|
|
17
|
+
export default adaptResponseEncodingToDownstream;
|