@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,1011 @@
|
|
|
1
|
+
import { JwtAlgo } from '../types';
|
|
2
|
+
import Route from './Route';
|
|
3
|
+
import Request from './Request';
|
|
4
|
+
import Response from './Response';
|
|
5
|
+
import BackendOptions from './BackendOptions';
|
|
6
|
+
import { CacheOptions } from './CacheOptions';
|
|
7
|
+
import RequestContext from './RequestContext';
|
|
8
|
+
import { BaseResponseWriter, CookieOptions } from './BaseResponseWriter';
|
|
9
|
+
export declare const FAR_FUTURE_TTL: number;
|
|
10
|
+
/**
|
|
11
|
+
* The API that is provided to route callbacks.
|
|
12
|
+
*/
|
|
13
|
+
export default class ResponseWriter extends BaseResponseWriter {
|
|
14
|
+
private params;
|
|
15
|
+
request: Request;
|
|
16
|
+
response: Response;
|
|
17
|
+
protected route: Route;
|
|
18
|
+
private streaming;
|
|
19
|
+
private context;
|
|
20
|
+
private cacheKey?;
|
|
21
|
+
private preCacheRequestActions;
|
|
22
|
+
private postCacheRequestActions;
|
|
23
|
+
private createResponseAction?;
|
|
24
|
+
private preCacheResponseActions;
|
|
25
|
+
private postCacheResponseActions;
|
|
26
|
+
/**
|
|
27
|
+
* @param req The request
|
|
28
|
+
* @param res The response
|
|
29
|
+
* @param route The route
|
|
30
|
+
* @param defaultBackend The default backend for proxy when none is provided
|
|
31
|
+
*/
|
|
32
|
+
constructor(req: Request, res: Response, route: Route, context: RequestContext);
|
|
33
|
+
/**
|
|
34
|
+
* Called at the end of the request to send the response back to the browser. Methods like proxy,
|
|
35
|
+
* serveStatic, and render will replace this method with one that actually sends a response.
|
|
36
|
+
* @private
|
|
37
|
+
* @returns True if there send response was defined and invoked, otherwise false.
|
|
38
|
+
*/
|
|
39
|
+
sendResponse({ beforeResponse }?: {
|
|
40
|
+
beforeResponse?: Function;
|
|
41
|
+
}): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Logs the cache status when running locally with caching is enabled
|
|
44
|
+
*/
|
|
45
|
+
private logCacheStatus;
|
|
46
|
+
/**
|
|
47
|
+
* Helper function to simplify calling interpolateParams()
|
|
48
|
+
*/
|
|
49
|
+
private interpolateParams;
|
|
50
|
+
/**
|
|
51
|
+
* Copies the body, headers, and status from the cached response
|
|
52
|
+
* to the outgoing response.
|
|
53
|
+
* @param cachedResponse The cached response
|
|
54
|
+
*/
|
|
55
|
+
private applyCachedResponse;
|
|
56
|
+
/**
|
|
57
|
+
* Rejects the request with status 412 and returns false if ?layer0_prefetch is present and
|
|
58
|
+
* no cached response was found.
|
|
59
|
+
*/
|
|
60
|
+
private validatePrefetch;
|
|
61
|
+
/**
|
|
62
|
+
* @param action
|
|
63
|
+
*/
|
|
64
|
+
private setCreateResponseAction;
|
|
65
|
+
/**
|
|
66
|
+
* Redirects the browser to a new location.
|
|
67
|
+
* Query params from the original request are added to the redirect URL
|
|
68
|
+
*
|
|
69
|
+
* **Examples**
|
|
70
|
+
*
|
|
71
|
+
* ```
|
|
72
|
+
* new Router()
|
|
73
|
+
* .get('/p/:productId', ({ redirect }) => {
|
|
74
|
+
* return redirect('/products/:productId', { statusCode: 301 })
|
|
75
|
+
* })
|
|
76
|
+
*
|
|
77
|
+
* // Extract id from route and apply as query string
|
|
78
|
+
* new Router()
|
|
79
|
+
* .get('/p/:productId', ({ redirect }) => {
|
|
80
|
+
* return redirect('/product', { query: { id: ':productId' }})
|
|
81
|
+
* })
|
|
82
|
+
*
|
|
83
|
+
* // Extract id from query string and apply to route
|
|
84
|
+
* new Router()
|
|
85
|
+
* .get({ path: '/p', query: { id: ':id' } }, ({ redirect }) => {
|
|
86
|
+
* return redirect('/product/:id')
|
|
87
|
+
* })
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @param to The URL to which the browser will be redirected.
|
|
91
|
+
* @param options
|
|
92
|
+
* @param options.statusCode The HTTP status to return. Defaults to 301
|
|
93
|
+
* @param options.query Key-value object of query strings to be added to the redirect url
|
|
94
|
+
*/
|
|
95
|
+
redirect: (to: string, options?: RedirectOptions) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Relays the request to the specified backend.
|
|
98
|
+
*
|
|
99
|
+
* **Example**
|
|
100
|
+
*
|
|
101
|
+
* ```
|
|
102
|
+
* new Router()
|
|
103
|
+
* .get('/some/path/with/:variable', ({ proxy }) => {
|
|
104
|
+
* proxy('legacy', { path: '/some/other/path/with/:variable' })
|
|
105
|
+
* })
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* In this example, we relay the request to the "legacy" backend. In this case, `layer0.config.js` must
|
|
109
|
+
* contain a definition for the `legacy` backend. For example:
|
|
110
|
+
*
|
|
111
|
+
* ```
|
|
112
|
+
* // layer0.config.js
|
|
113
|
+
*
|
|
114
|
+
* module.exports = {
|
|
115
|
+
* backends: {
|
|
116
|
+
* legacy: {
|
|
117
|
+
* domainOrIp: 'legacy.domain.com',
|
|
118
|
+
* hostHeader: 'domain.com'
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @param backend The name of one of the backends in your `layer0.config.js` file.
|
|
125
|
+
* @param options
|
|
126
|
+
* @returns A promise the resolves once the response has been fetched from the upstream site.
|
|
127
|
+
*/
|
|
128
|
+
proxy: (backend: string, options?: ProxyOptions | undefined) => Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Calls the provided callback to send a response.
|
|
131
|
+
* @param cb Render callback function
|
|
132
|
+
* @deprecated
|
|
133
|
+
*/
|
|
134
|
+
render: (cb: (request: Request, proxy: (backend: string, options: ProxyOptions) => void, params: any) => void) => void;
|
|
135
|
+
/**
|
|
136
|
+
* Renders a result in Layer0's serverless cloud using your application. Use this method
|
|
137
|
+
* to respond with an SSR or API result from your application.
|
|
138
|
+
* @param options Options for transforming the request sent to your app and the response received from it.
|
|
139
|
+
*/
|
|
140
|
+
renderWithApp: (options?: ProxyOptions | undefined) => Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Streams the result from a backend. Can only be used in development for things
|
|
143
|
+
* like hot-module reloading.
|
|
144
|
+
* @param backend The name of the backend to connect to
|
|
145
|
+
* @private
|
|
146
|
+
*/
|
|
147
|
+
stream: (backend: string) => void;
|
|
148
|
+
/**
|
|
149
|
+
* Proxies the response from a given host
|
|
150
|
+
* @private
|
|
151
|
+
* @param backendConfig The backend config
|
|
152
|
+
* @param options
|
|
153
|
+
*/
|
|
154
|
+
proxyHost: (backendConfig: BackendOptions, { path, transformRequest, transformResponse, headers, removeEmptySearchParamValues, }?: ProxyOptions) => Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Rewrites the request path.
|
|
157
|
+
*
|
|
158
|
+
* Example:
|
|
159
|
+
*
|
|
160
|
+
* ```js
|
|
161
|
+
* router.get('/products/:id', ({ updatePath }) => {
|
|
162
|
+
* updatePath('/p/:id')
|
|
163
|
+
* })
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @param destination a new route path, which can include params captured from the original path
|
|
167
|
+
*/
|
|
168
|
+
updatePath: (destination: string) => void;
|
|
169
|
+
/**
|
|
170
|
+
* Updates the request's parameters based on a new path and route pattern. This is, in effect,
|
|
171
|
+
* an implementation of Next.js rewrites, put here instead of NextRoutes in anticipation of other frameworks
|
|
172
|
+
* implementing the same spec as many of them "follow the leader".
|
|
173
|
+
*
|
|
174
|
+
* **example**:
|
|
175
|
+
*
|
|
176
|
+
* ```js
|
|
177
|
+
* res.rewrite('/category/boys/:slug*', '/category/:slug*')
|
|
178
|
+
* // result: request.params will be { slug: ['category', 'boys'] }
|
|
179
|
+
* ```
|
|
180
|
+
* @private
|
|
181
|
+
* @param destination A destination path, which may contain path variables.
|
|
182
|
+
* @param pattern The path pattern for the destination route we're emulating
|
|
183
|
+
*/
|
|
184
|
+
rewrite: (destination: string, pattern: string) => void;
|
|
185
|
+
/**
|
|
186
|
+
* Responds with a static asset from the specified path.
|
|
187
|
+
*
|
|
188
|
+
* **Example**
|
|
189
|
+
*
|
|
190
|
+
* ```js
|
|
191
|
+
* serveStatic('path/to/asset/from/app/root')
|
|
192
|
+
* ```
|
|
193
|
+
*
|
|
194
|
+
* You can also use variables in the asset path. For example, to return files under the `assets` directory
|
|
195
|
+
* when the url starts with `/static`:
|
|
196
|
+
*
|
|
197
|
+
* ```
|
|
198
|
+
* new Router()
|
|
199
|
+
* .get('/static/:path*', ({ serveStatic }) => {
|
|
200
|
+
* serveStatic('assets/:path*')
|
|
201
|
+
* })
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* Notes:
|
|
205
|
+
* - if a folder contains an 'index.html', that page is also served when requesting the parent folder route.
|
|
206
|
+
* Let's take the example of /posts/1 that will render /posts/1/index.html)
|
|
207
|
+
* They are multiple components involved in this rewrite to make it work with S3 storage:
|
|
208
|
+
* 1. DeploymentBuilder creates and bundles an assets-aliases.json file, that indicates that
|
|
209
|
+
* '/posts/1' should point to '/posts/1/index.html' asset file.
|
|
210
|
+
* 2. layer0-subaccount-infra/components/deploy-lambda/src/deploy.js re-uploads '/posts/1/index.html'
|
|
211
|
+
* as '/posts/1' s3 key, which works because S3 is a key based storage and not a filesystem.
|
|
212
|
+
* It's a bit of a hack and takes extra space, but allows root document rendering.
|
|
213
|
+
* 3. serveStatic(), both in ResponseWriter ad EdgeResponseWriter, remove any trailing slash on path
|
|
214
|
+
* so that both '/posts/1/' and '/posts/1' match the '/posts/1' S3 file
|
|
215
|
+
*
|
|
216
|
+
* - We did not use S3 built-in Static Website feature for multiple reasons:
|
|
217
|
+
* 1. It is http only
|
|
218
|
+
* 2. /build-slug/public/posts/ renders /build-slug/public/posts/index.html correctly, but /build-slug/public/posts
|
|
219
|
+
* without a trailing slash redirects to /build-slug/public/posts/.
|
|
220
|
+
* While it's easy to rewrite the path and remove trailing slashes, we actually do, it's not easy
|
|
221
|
+
* to add missing trailing slash as we don't know beforehand if the route is a directory or a file.
|
|
222
|
+
* Having a redirect on every route is not acceptable either.
|
|
223
|
+
* The Location header would also need to be rewritten to be relative to the actual website and
|
|
224
|
+
* not the bucket prefix, but that's manageable.
|
|
225
|
+
*
|
|
226
|
+
* - ISG/ISR:
|
|
227
|
+
* When handling a request for a static asset that is not in S3, the request follows this path:
|
|
228
|
+
*
|
|
229
|
+
*```
|
|
230
|
+
* Browser => Edge => S3 (requested asset, which results in a 404)
|
|
231
|
+
* Edge => Buffer Proxy => S3 (options.loadingPage, if provided) => Response returned
|
|
232
|
+
* => Edge => Buffer Proxy => Lambda => BehindEdgeResponseWriter => options.onNotFound => SSR (then this response is cached for the next request)
|
|
233
|
+
*```
|
|
234
|
+
*
|
|
235
|
+
* Note that BehindEdgeResponseWriter is the key here. It overrides serveStatic and if options.onNotFound is provided, it will always be called.
|
|
236
|
+
*
|
|
237
|
+
* @param path The relative path to the asset from the app's root directory. You can reference path variables using `:variable`.
|
|
238
|
+
* @param options The different options to serving static assets including fallback to compute
|
|
239
|
+
* @returns A promise the resolves once the asset has been fetched from storage.
|
|
240
|
+
*/
|
|
241
|
+
serveStatic: (path: string, options?: ServeStaticOptions) => Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* Sets the caching behavior for both browser and edge.
|
|
244
|
+
*
|
|
245
|
+
* **Example**
|
|
246
|
+
*
|
|
247
|
+
* ```
|
|
248
|
+
* new Router()
|
|
249
|
+
* .get('/p/:productId', ({ cache, proxy }) => {
|
|
250
|
+
* cache({
|
|
251
|
+
* browser: {
|
|
252
|
+
* maxAgeSeconds: 0,
|
|
253
|
+
* serviceWorkerSeconds: 60 * 60, // 1 hour
|
|
254
|
+
* },
|
|
255
|
+
* edge: {
|
|
256
|
+
* maxAgeSeconds: 60 * 60 * 24, // 24 hours
|
|
257
|
+
* staleWhileRevalidateSeconds: 60 * 60 // 1 hour
|
|
258
|
+
* }
|
|
259
|
+
* })
|
|
260
|
+
* proxy('origin')
|
|
261
|
+
* })
|
|
262
|
+
* ```
|
|
263
|
+
*
|
|
264
|
+
* The `cache()` method can be called in the same route where the response is sent, or any prior route. For example,
|
|
265
|
+
* with Next.js, it is common to use the next plugin to automatically inherit page routes based on Next.js conventions,
|
|
266
|
+
* and use Layer0 router simply to add caching:
|
|
267
|
+
*
|
|
268
|
+
* ```
|
|
269
|
+
* import { Router } = from '@layer0/core/router'
|
|
270
|
+
* import { createNextPlugin } from '@layer0/next'
|
|
271
|
+
*
|
|
272
|
+
* const { nextMiddleware, renderNext } = createNextPlugin()
|
|
273
|
+
*
|
|
274
|
+
* new Router()
|
|
275
|
+
* .get('/p/:productId', ({ cache, proxy }) => {
|
|
276
|
+
* cache({
|
|
277
|
+
* browser: {
|
|
278
|
+
* maxAgeSeconds: 0,
|
|
279
|
+
* serviceWorkerSeconds: 60 * 60, // 1 hour
|
|
280
|
+
* },
|
|
281
|
+
* edge: {
|
|
282
|
+
* maxAgeSeconds: 60 * 60 * 24, // 24 hours
|
|
283
|
+
* staleWhileRevalidateSeconds: 60 * 60 // 1 hour
|
|
284
|
+
* }
|
|
285
|
+
* })
|
|
286
|
+
* proxy('origin')
|
|
287
|
+
* })
|
|
288
|
+
* .use(nextMiddleware)
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
cache: (options: CacheOptions) => void;
|
|
292
|
+
/**
|
|
293
|
+
* Adds or replaces a response header immediately before delivering the response downstream.
|
|
294
|
+
*
|
|
295
|
+
* **Example**
|
|
296
|
+
*
|
|
297
|
+
* ```
|
|
298
|
+
* new Router()
|
|
299
|
+
* .get('/some/path', ({ setResponseHeader, proxy }) => {
|
|
300
|
+
* proxy('origin')
|
|
301
|
+
* setResponseHeader('some-header', 'some-value')
|
|
302
|
+
* })
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* @param name The case-insensitive name of the response header
|
|
306
|
+
* @param value The value to set
|
|
307
|
+
*/
|
|
308
|
+
setResponseHeader: (name: string, value: string) => void;
|
|
309
|
+
private internalSetResponseHeader;
|
|
310
|
+
/**
|
|
311
|
+
* Alters a response header immediately before delivering the response downstream.
|
|
312
|
+
* Use this method to derive the new header value from the existing one.
|
|
313
|
+
*
|
|
314
|
+
* **Example**
|
|
315
|
+
*
|
|
316
|
+
* ```
|
|
317
|
+
* new Router()
|
|
318
|
+
* .get('/some/path', ({ updateResponseHeader, proxy }) => {
|
|
319
|
+
* proxy('origin')
|
|
320
|
+
* updateResponseHeader('some-header', /some-.*-part/gi, 'some-replacement')
|
|
321
|
+
* })
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* @param name The case-insensitive name of the response header
|
|
325
|
+
* @param match Regex to find the part that should be replaced.
|
|
326
|
+
* @param replace Value that will replace the matched part.
|
|
327
|
+
*/
|
|
328
|
+
updateResponseHeader: (name: string, match: RegExp, replace: string) => void;
|
|
329
|
+
private internalUpdateResponseHeader;
|
|
330
|
+
/**
|
|
331
|
+
* Removes a response header immediately before delivering the response downstream.
|
|
332
|
+
*
|
|
333
|
+
* **Example**
|
|
334
|
+
*
|
|
335
|
+
* ```
|
|
336
|
+
* new Router()
|
|
337
|
+
* .get('/some/path', ({ removeResponseHeader, proxy }) => {
|
|
338
|
+
* proxy('origin')
|
|
339
|
+
* removeResponseHeader('some-header')
|
|
340
|
+
* })
|
|
341
|
+
* ```
|
|
342
|
+
* @param name The case-insensitive name of the response header
|
|
343
|
+
*/
|
|
344
|
+
removeResponseHeader: (name: string) => void;
|
|
345
|
+
private internalRemoveResponseHeader;
|
|
346
|
+
/**
|
|
347
|
+
* Returns an array of values associated with all `set-cookie` headers.
|
|
348
|
+
*/
|
|
349
|
+
private getSetCookieValues;
|
|
350
|
+
/**
|
|
351
|
+
* Returns action function for the "add response cookie" operation.
|
|
352
|
+
*/
|
|
353
|
+
private getAddResponseCookieAction;
|
|
354
|
+
/**
|
|
355
|
+
* Adds a `set-cookie` header to the response before attempting to cache the response.
|
|
356
|
+
* This does not replace any cookies with the same name - for that you should use `updateUpstreamResponseCookie`.
|
|
357
|
+
* Furthermore, Layer0 does not cache responses with `set-cookie` so if you wish to add a cookie
|
|
358
|
+
* *after* the response is cached, you should use `addResponseCookie`.
|
|
359
|
+
*
|
|
360
|
+
* **Example**
|
|
361
|
+
*
|
|
362
|
+
* ```
|
|
363
|
+
* new Router()
|
|
364
|
+
* .get('/some/path', ({ addUpstreamResponseCookie, proxy }) => {
|
|
365
|
+
* proxy('origin')
|
|
366
|
+
* addUpstreamResponseCookie('my-cookie', 'my-cookie-value', { domain: 'test.com' })
|
|
367
|
+
* })
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* @param name Name of the cookie to add.
|
|
371
|
+
* @param value Value to set
|
|
372
|
+
* @param options Optional options to add to cookie
|
|
373
|
+
*/
|
|
374
|
+
addUpstreamResponseCookie: (name: string, value: string, options?: CookieOptions | undefined) => void;
|
|
375
|
+
/**
|
|
376
|
+
* Adds a `set-cookie` header to the response.
|
|
377
|
+
* This does not replace any cookies with the same name - for that you should use `updateResponseCookie`.
|
|
378
|
+
*
|
|
379
|
+
* **Example**
|
|
380
|
+
*
|
|
381
|
+
* ```
|
|
382
|
+
* new Router()
|
|
383
|
+
* .get('/some/path', ({ addResponseCookie, proxy }) => {
|
|
384
|
+
* proxy('origin')
|
|
385
|
+
* addResponseCookie('my-cookie', 'my-cookie-value', { domain: 'test.com' })
|
|
386
|
+
* })
|
|
387
|
+
* ```
|
|
388
|
+
*
|
|
389
|
+
* @param name Name of the cookie to add.
|
|
390
|
+
* @param value Value to set
|
|
391
|
+
* @param options Optional options to add to cookie
|
|
392
|
+
*/
|
|
393
|
+
addResponseCookie: (name: string, value: string, options?: CookieOptions | undefined) => void;
|
|
394
|
+
/**
|
|
395
|
+
* Returns action function for the "update response cookie" operation.
|
|
396
|
+
*
|
|
397
|
+
* Notes:
|
|
398
|
+
* - Cookie names are case sensitive so we use case sensitive comparison.
|
|
399
|
+
*/
|
|
400
|
+
private getUpdateResponseCookieAction;
|
|
401
|
+
/**
|
|
402
|
+
* Updates a `set-cookie` header in the response before attempting to cache the response.
|
|
403
|
+
* If there are multiple cookies with the same name, all of them will be updated.
|
|
404
|
+
*
|
|
405
|
+
* **Example**
|
|
406
|
+
*
|
|
407
|
+
* ```
|
|
408
|
+
* new Router()
|
|
409
|
+
* .get('/some/path', ({ updateUpstreamResponseCookie, proxy }) => {
|
|
410
|
+
* proxy('origin')
|
|
411
|
+
* updateUpstreamResponseCookie('my-cookie', /Domain=.+;/, 'Domain=mydomain.com;')
|
|
412
|
+
* })
|
|
413
|
+
* ```
|
|
414
|
+
*
|
|
415
|
+
* @param name Case-insensitive name of the cookie to update
|
|
416
|
+
* @param match Regex to find the part that should be replaced.
|
|
417
|
+
* @param replace Value that will replace the matched part.
|
|
418
|
+
*/
|
|
419
|
+
updateUpstreamResponseCookie: (name: string, match: RegExp, replace: string) => void;
|
|
420
|
+
/**
|
|
421
|
+
* Updates a `set-cookie` header in the response. If there are multiple cookies
|
|
422
|
+
* with the same name, all of them will be updated.
|
|
423
|
+
*
|
|
424
|
+
* **Example**
|
|
425
|
+
*
|
|
426
|
+
* ```
|
|
427
|
+
* new Router()
|
|
428
|
+
* .get('/some/path', ({ updateResponseCookie, proxy }) => {
|
|
429
|
+
* proxy('origin')
|
|
430
|
+
* updateResponseCookie('my-cookie', /Domain=.+;/, 'Domain=mydomain.com;')
|
|
431
|
+
* })
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* @param name Case-insensitive name of the cookie to update
|
|
435
|
+
* @param match Regex to find the part that should be replaced.
|
|
436
|
+
* @param replace Value that will replace the matched part.
|
|
437
|
+
*/
|
|
438
|
+
updateResponseCookie: (name: string, match: RegExp, replace: string) => void;
|
|
439
|
+
/**
|
|
440
|
+
* Returns action function for the "remove response cookie" operation.
|
|
441
|
+
*
|
|
442
|
+
* Notes:
|
|
443
|
+
* - Cookie names are case sensitive so we use case sensitive comparison.
|
|
444
|
+
*/
|
|
445
|
+
private getRemoveResponseCookieAction;
|
|
446
|
+
/**
|
|
447
|
+
* Removes a specific `set-cookie` header from the response before attempting to cache the response.
|
|
448
|
+
* If you wish to remove all such headers use `removeUpstreamHeader`.
|
|
449
|
+
*
|
|
450
|
+
* **Example**
|
|
451
|
+
*
|
|
452
|
+
* ```
|
|
453
|
+
* new Router()
|
|
454
|
+
* .get('/some/path', ({ removeUpstreamResponseCookie, proxy }) => {
|
|
455
|
+
* proxy('origin')
|
|
456
|
+
* removeUpstreamResponseCookie('my-cookie')
|
|
457
|
+
* })
|
|
458
|
+
* ```
|
|
459
|
+
* @param name The case-insensitive name of the cookie
|
|
460
|
+
*/
|
|
461
|
+
removeUpstreamResponseCookie: (name: string) => void;
|
|
462
|
+
/**
|
|
463
|
+
* Removes a specific `set-cookie` header from the response.
|
|
464
|
+
* If you wish to remove all such headers use `removeHeader`.
|
|
465
|
+
*
|
|
466
|
+
* **Example**
|
|
467
|
+
*
|
|
468
|
+
* ```
|
|
469
|
+
* new Router()
|
|
470
|
+
* .get('/some/path', ({ removeResponseCookie, proxy }) => {
|
|
471
|
+
* proxy('origin')
|
|
472
|
+
* removeResponseCookie('my-cookie')
|
|
473
|
+
* })
|
|
474
|
+
* ```
|
|
475
|
+
* @param name The case-insensitive name of the cookie
|
|
476
|
+
*/
|
|
477
|
+
removeResponseCookie: (name: string) => void;
|
|
478
|
+
/**
|
|
479
|
+
* Adds or replaces an upstream response header before attempting to cache the response.
|
|
480
|
+
* In local development, this is the same as calling `setResponseHeader` but on edge, it adds
|
|
481
|
+
* a header immediately after the upstream fetch has finished.
|
|
482
|
+
*
|
|
483
|
+
* **Example**
|
|
484
|
+
*
|
|
485
|
+
* ```
|
|
486
|
+
* new Router()
|
|
487
|
+
* .get('/some/path', ({ setUpstreamResponseHeader, proxy }) => {
|
|
488
|
+
* proxy('origin')
|
|
489
|
+
* setUpstreamResponseHeader('x-0-surrogate-key', 'proxy=origin')
|
|
490
|
+
* })
|
|
491
|
+
* ```
|
|
492
|
+
*
|
|
493
|
+
* @param name The case-insensitive name of the response header
|
|
494
|
+
* @param value The value to set
|
|
495
|
+
*/
|
|
496
|
+
setUpstreamResponseHeader: (name: string, value: string) => void;
|
|
497
|
+
/**
|
|
498
|
+
* Alters an upstream response header before attempting to cache the response.
|
|
499
|
+
* Use this method to derive the new header value from the existing one.
|
|
500
|
+
* In local development this is same as calling `updateResponseHeader` but on
|
|
501
|
+
* edge it updates a header immediately after the upstream fetch has finished.
|
|
502
|
+
*
|
|
503
|
+
* **Example**
|
|
504
|
+
*
|
|
505
|
+
* ```
|
|
506
|
+
* new Router()
|
|
507
|
+
* .get('/some/path', ({ updateUpstreamResponseHeader, proxy }) => {
|
|
508
|
+
* proxy('origin')
|
|
509
|
+
* updateUpstreamResponseHeader('cache-control', /public/gi, 'private')
|
|
510
|
+
* })
|
|
511
|
+
* ```
|
|
512
|
+
*
|
|
513
|
+
* @param name The case-insensitive name of the response header
|
|
514
|
+
* @param match Regex to find the part that should be replaced.
|
|
515
|
+
* @param replace Value that will replace the matched part.
|
|
516
|
+
*/
|
|
517
|
+
updateUpstreamResponseHeader: (name: string, match: RegExp, replace: string) => void;
|
|
518
|
+
/**
|
|
519
|
+
* Removes a response header before attempting to cache the response.
|
|
520
|
+
* In local development this is same as calling `updateUpstreamResponseHeader` but
|
|
521
|
+
* on edge it removes a header immediately after the upstream fetch has finished.
|
|
522
|
+
*
|
|
523
|
+
* **Example**
|
|
524
|
+
*
|
|
525
|
+
* ```
|
|
526
|
+
* new Router()
|
|
527
|
+
* .get('/some/path', ({ removeUpstreamResponseHeader, proxy }) => {
|
|
528
|
+
* proxy('origin')
|
|
529
|
+
* removeUpstreamResponseHeader(HTTP_HEADERS.setCookie)
|
|
530
|
+
* })
|
|
531
|
+
* ```
|
|
532
|
+
* @param name The case-insensitive name of the response header
|
|
533
|
+
*/
|
|
534
|
+
removeUpstreamResponseHeader: (name: string) => void;
|
|
535
|
+
/**
|
|
536
|
+
* Adds or replaces a request header.
|
|
537
|
+
*
|
|
538
|
+
* **Example**
|
|
539
|
+
*
|
|
540
|
+
* ```
|
|
541
|
+
* new Router()
|
|
542
|
+
* .get('/some/path', ({ setRequestHeader, proxy }) => {
|
|
543
|
+
* setRequestHeader('some-header', 'some-value')
|
|
544
|
+
* proxy('origin')
|
|
545
|
+
* })
|
|
546
|
+
* ```
|
|
547
|
+
*
|
|
548
|
+
* @param name The case-insensitive name of the request header
|
|
549
|
+
* @param value The value to set
|
|
550
|
+
*/
|
|
551
|
+
setRequestHeader: (name: string, value: string) => void;
|
|
552
|
+
/**
|
|
553
|
+
* Returns true if the object is in the running immediately mode.
|
|
554
|
+
* When object is in the running immediately mode, all otherwise
|
|
555
|
+
* scheduled actions like header transform operations, are immediately
|
|
556
|
+
* executed.
|
|
557
|
+
* @private
|
|
558
|
+
*/
|
|
559
|
+
private get runningImmediately();
|
|
560
|
+
/**
|
|
561
|
+
* Keeps count of the number of times we have started to execute any
|
|
562
|
+
* workload immediately. When the counter is at zero, we are not in
|
|
563
|
+
* the immediate execution mode.
|
|
564
|
+
*/
|
|
565
|
+
private runImmediatelyDepthCounter;
|
|
566
|
+
/**
|
|
567
|
+
* Runs the given callback immediately, switching the response writer object
|
|
568
|
+
* into immediate execution mode.
|
|
569
|
+
*
|
|
570
|
+
* @param callback
|
|
571
|
+
*/
|
|
572
|
+
private runImmediately;
|
|
573
|
+
/**
|
|
574
|
+
* Either schedules the action for the later execution or, when running immediately,
|
|
575
|
+
* executes it right away.
|
|
576
|
+
*
|
|
577
|
+
* @param phase Array of Functions belonging to the specific execution phase (pre-cache request, post-cache request, etc)
|
|
578
|
+
* @param action Action to be executed either immediately or put into the execution array
|
|
579
|
+
*/
|
|
580
|
+
private scheduleExecution;
|
|
581
|
+
/**
|
|
582
|
+
* Alters a request header. Use this method to derive the new header value from the existing one.
|
|
583
|
+
*
|
|
584
|
+
* **Example**
|
|
585
|
+
*
|
|
586
|
+
* ```
|
|
587
|
+
* new Router()
|
|
588
|
+
* .get('/some/path', ({ updateRequestHeader, proxy }) => {
|
|
589
|
+
* updateRequestHeader('some-header', /some-.*-part/gi, 'some-replacement')
|
|
590
|
+
* proxy('origin')
|
|
591
|
+
* })
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* @param name The case-insensitive name of the request header
|
|
595
|
+
* @param match Regex to find the part that should be replaced.
|
|
596
|
+
* @param replace Value that will replace the matched part.
|
|
597
|
+
*/
|
|
598
|
+
updateRequestHeader: (name: string, match: RegExp, replace: string) => void;
|
|
599
|
+
/**
|
|
600
|
+
* Removes a request header.
|
|
601
|
+
*
|
|
602
|
+
* **Example**
|
|
603
|
+
*
|
|
604
|
+
* ```
|
|
605
|
+
* new Router()
|
|
606
|
+
* .get('/some/path', async ({ removeRequestHeader, proxy }) => {
|
|
607
|
+
* removeRequestHeader('some-header')
|
|
608
|
+
* proxy('origin')
|
|
609
|
+
* })
|
|
610
|
+
* ```
|
|
611
|
+
* @param name The case-insensitive name of the request header
|
|
612
|
+
*/
|
|
613
|
+
removeRequestHeader: (name: string) => void;
|
|
614
|
+
/**
|
|
615
|
+
* Returns the service worker with proper edge and browser cache headers
|
|
616
|
+
* @param path The path to the service worker relative to the root directory of your app
|
|
617
|
+
*
|
|
618
|
+
* **Example**
|
|
619
|
+
*
|
|
620
|
+
* ```js
|
|
621
|
+
* new Router()
|
|
622
|
+
* .get('/service-worker.js', ({ serviceWorker }) => {
|
|
623
|
+
* serviceWorker('dist/service-worker.js')
|
|
624
|
+
* })
|
|
625
|
+
* ```
|
|
626
|
+
*/
|
|
627
|
+
serviceWorker: (path: string) => void;
|
|
628
|
+
/**
|
|
629
|
+
* Serves an HTML app shell from a static file.
|
|
630
|
+
* @param indexHtmlPath The path to the app shell html file
|
|
631
|
+
*
|
|
632
|
+
* **Example**
|
|
633
|
+
*
|
|
634
|
+
* ```js
|
|
635
|
+
* new Router()
|
|
636
|
+
* .fallback(({ appShell }) => {
|
|
637
|
+
* appShell('dist/index.html')
|
|
638
|
+
* })
|
|
639
|
+
* ```
|
|
640
|
+
*/
|
|
641
|
+
appShell: (indexHtmlPath: string) => void;
|
|
642
|
+
/**
|
|
643
|
+
* Sends the necessary response headers to allow CORS
|
|
644
|
+
* @param config
|
|
645
|
+
*
|
|
646
|
+
* **Example**
|
|
647
|
+
*
|
|
648
|
+
* ```js
|
|
649
|
+
* new Router()
|
|
650
|
+
* .match('/api/:path*', ({ allowCors }) => {
|
|
651
|
+
* allowCors({
|
|
652
|
+
* origin: '*', // this is the default
|
|
653
|
+
* methods: ['get', 'post'],
|
|
654
|
+
* headers: ['x-some-header'],
|
|
655
|
+
* maxAge: 60 * 60, // one hour
|
|
656
|
+
* credentials: true
|
|
657
|
+
* })
|
|
658
|
+
* })
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
allowCors: (config?: CorsOptions) => void;
|
|
662
|
+
/**
|
|
663
|
+
* Sends content back to client. If content is a string, the respons will be sent
|
|
664
|
+
* directly from the edge. If it is a function, the request will be computed by a JavaScript worker.
|
|
665
|
+
*
|
|
666
|
+
* **Example**
|
|
667
|
+
*
|
|
668
|
+
* ```
|
|
669
|
+
* new Router()
|
|
670
|
+
* .get('/some/path', ({ send }) => {
|
|
671
|
+
* return send('<html><body>Hello World!</body></html>', 200, 'OK')
|
|
672
|
+
* })
|
|
673
|
+
* ```
|
|
674
|
+
* @param content The response body as a string
|
|
675
|
+
* @param statusCode The status to send
|
|
676
|
+
* @param statusMessage The status message to send
|
|
677
|
+
*/
|
|
678
|
+
send: (content: string | (() => string), statusCode?: number, statusMessage?: string | undefined) => void;
|
|
679
|
+
/**
|
|
680
|
+
* Execute the provided callback function in the cloud. The callback is passed the request and the response.
|
|
681
|
+
*
|
|
682
|
+
* Use this method when you need to compute a response in the cloud rather than at the edge or at build time. A common example
|
|
683
|
+
* is when the response must be computed based on request parameters, headers, or cookies.
|
|
684
|
+
*
|
|
685
|
+
* A common example is to look up the destination for a redirect from an external API:
|
|
686
|
+
*
|
|
687
|
+
* ```js
|
|
688
|
+
* new Router()
|
|
689
|
+
* .get('/products/:id', ({ redirect, compute }) => {
|
|
690
|
+
* compute(async (request, response) => {
|
|
691
|
+
* const destination = await getDestinationFromAPI(request.params.id)
|
|
692
|
+
* redirect(destination)
|
|
693
|
+
* })
|
|
694
|
+
* })
|
|
695
|
+
* ```
|
|
696
|
+
*
|
|
697
|
+
* This method can be combined with `cache` to compute responses in the cloud and cache them at edge:
|
|
698
|
+
*
|
|
699
|
+
* ```js
|
|
700
|
+
* new Router()
|
|
701
|
+
* .get('/products/:id', ({ cache, redirect, compute }) => {
|
|
702
|
+
* cache({
|
|
703
|
+
* edge: {
|
|
704
|
+
* maxAgeSeconds: 60 * 60 * 24,
|
|
705
|
+
* staleWhileRevalidateSeconds: 60 * 60,
|
|
706
|
+
* }
|
|
707
|
+
* })
|
|
708
|
+
* compute(async (request, response) => {
|
|
709
|
+
* const destination = await getDestinationFromAPI(request.params.id)
|
|
710
|
+
* redirect(destination)
|
|
711
|
+
* })
|
|
712
|
+
* })
|
|
713
|
+
* ```
|
|
714
|
+
*
|
|
715
|
+
* Note: when calling `compute` in combination with `serveStatic`, the result of the `serveStatic` must be
|
|
716
|
+
* awaited in order to get the result from `serveStatic`, otherwise only reslut of the `compute` method
|
|
717
|
+
* will be returned.
|
|
718
|
+
*
|
|
719
|
+
* ```js
|
|
720
|
+
* new Router()
|
|
721
|
+
* .get('/products/:id', ({ redirect, compute }) => {
|
|
722
|
+
* compute(async (request, response) => {
|
|
723
|
+
* const destination = await getDestinationFromAPI(request.params.id)
|
|
724
|
+
* await serveStatic(destination)
|
|
725
|
+
* })
|
|
726
|
+
* })
|
|
727
|
+
* ```
|
|
728
|
+
*
|
|
729
|
+
* @param callback A function to run in the cloud to compute the response
|
|
730
|
+
*/
|
|
731
|
+
compute: (callback: (request: Request, response: Response) => void | Promise<void>) => void;
|
|
732
|
+
/**
|
|
733
|
+
* Clears response action. This is required for compute and error pages. Error pages must alter the initial response and execute the error routes separately.
|
|
734
|
+
*
|
|
735
|
+
* @private
|
|
736
|
+
* @returns
|
|
737
|
+
*/
|
|
738
|
+
clearResponseAction(): this;
|
|
739
|
+
/**
|
|
740
|
+
* Send json error response to client
|
|
741
|
+
* @private
|
|
742
|
+
* @param err
|
|
743
|
+
*/
|
|
744
|
+
onRouteError: (err: Error) => void;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Options for the verifyJwt method. `header` and `cookie`
|
|
748
|
+
* are mutually exclusive. Do not attempt to specify both, one
|
|
749
|
+
* will take precedence non-deterministically. Consider the ffollowing example:
|
|
750
|
+
*
|
|
751
|
+
* ```typescript
|
|
752
|
+
* new Router({}).match(
|
|
753
|
+
* '/protected', ({verifyJwt}) => {
|
|
754
|
+
* verifyJwt({
|
|
755
|
+
* algo: 'HS256',
|
|
756
|
+
* secret: 'supersecret',
|
|
757
|
+
* cookie: 'next-auth.session-token',
|
|
758
|
+
* redirectExpiredAbsent: '/expired',
|
|
759
|
+
* redirectInvalid: '/invalid',
|
|
760
|
+
* returnUrlParamName: 'origUrl',
|
|
761
|
+
* })
|
|
762
|
+
* }
|
|
763
|
+
* )
|
|
764
|
+
* ```
|
|
765
|
+
*
|
|
766
|
+
* On requests to `/protected` this will check for the presense of a symetrically signed (HM256,
|
|
767
|
+
* shared secret) HWT in the `Cookie: next-auth.session-token=eyJh...;` part of the cookie, redirecting
|
|
768
|
+
* expired to `/expired?origUrl=%2Fprotected` and invalid JWTs to `/expired?origUrl=%2Finvalid`
|
|
769
|
+
* (See {@linkcode redirectExpiredAbsent} and {@linkcode redirectInvalid} for an explanation of
|
|
770
|
+
* the difference).
|
|
771
|
+
*
|
|
772
|
+
* If neither {@linkcode redirectExpiredAbsent} nor {@linkcode redirectInvalid} are specified, then the value of {@linkcode returnUrlParamName} is ignored, and all requests are answered with an [`403 Forbidden`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403).
|
|
773
|
+
*/
|
|
774
|
+
export interface VerifyJwtOptions {
|
|
775
|
+
/**
|
|
776
|
+
* JWT algorithm, both symmetric and asymmetric are supported. See {@linkcode JwtAlgo}.
|
|
777
|
+
*
|
|
778
|
+
* **Important:** `{"algo":"none"}` is explicitly unsupported. See [here](https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/) for more information.
|
|
779
|
+
*
|
|
780
|
+
* @type {typeof JwtAlgo::HS256}
|
|
781
|
+
*/
|
|
782
|
+
algo: JwtAlgo;
|
|
783
|
+
/** The secret, this should either be an armoued (PEM encoded including header and fooder)
|
|
784
|
+
* public key for the asymmetric algorithms, or a simple secret string for the
|
|
785
|
+
* symmetric algorithms. Symmetric algorithms (`HM..`) use the same secret for signing
|
|
786
|
+
* and verification which is insecure if the client code (e.g a single-page-app) has the secret
|
|
787
|
+
* embedded in the bundle.
|
|
788
|
+
*
|
|
789
|
+
* Use a symmetric algorightm (see {@linkcode JwtAlgo} for more
|
|
790
|
+
* information) to use a public and private key to independently verify (public key) and
|
|
791
|
+
* sign (private key) the tokens. The `ES...` family produces the smallest asymmetric
|
|
792
|
+
* signatures, if overhead introduced by using JWTs is a concern.
|
|
793
|
+
*
|
|
794
|
+
* If using an asymmetric algorithm the value provided must be the **public** key provided in
|
|
795
|
+
* [RFC7468](https://datatracker.ietf.org/doc/html/rfc7468) PEM format, such as:
|
|
796
|
+
*
|
|
797
|
+
* ```
|
|
798
|
+
* -----BEGIN PUBLIC KEY-----
|
|
799
|
+
* MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEn1LlwLN/KBYQRVH6HfIMTzfEqJOVztLe
|
|
800
|
+
* kLchp2hi78cCaMY81FBlYs8J9l7krc+M4aBeCGYFjba+hiXttJWPL7ydlE+5UG4U
|
|
801
|
+
* Nkn3Eos8EiZByi9DVsyfy9eejh+8AXgp
|
|
802
|
+
* -----END PUBLIC KEY-----
|
|
803
|
+
* ```
|
|
804
|
+
*/
|
|
805
|
+
secret: String;
|
|
806
|
+
/** The header to extract the token from. If the value of the header is prefixed with
|
|
807
|
+
* `.*Bearer\ `, this will be ignored and only the following bytes decoded as a JWT.
|
|
808
|
+
* e.g `Authorization: Bearer eyJh...`.
|
|
809
|
+
*/
|
|
810
|
+
header?: String;
|
|
811
|
+
/** The cookie key to extract the token from. e.g given a request header
|
|
812
|
+
* `Cookie: a=eyJh...;b=session;c=etc`, setting the value `a` here will
|
|
813
|
+
* extract the `a` cookie.
|
|
814
|
+
*/
|
|
815
|
+
cookie?: String;
|
|
816
|
+
/** The redirect URL to use when the JWT is expired, or absent. JWT expiry complies
|
|
817
|
+
* with RFC7519 `exp` claim behaviour. JWTs rejected due to `nbf` (not before) claim
|
|
818
|
+
* invalidity are also subject to this redirect, they may be understood as "expired" in
|
|
819
|
+
* that they not valid yet. Invalid tokens are handled separately in {@linkcode redirectInvalid}.
|
|
820
|
+
* For either case of redirect, you may specify {@linkcode returnUrlParamName} to indicate how
|
|
821
|
+
* the URL redirecting the client should be forwarded; this can be used to send a client to the
|
|
822
|
+
* login page and allow a seamless return.
|
|
823
|
+
*/
|
|
824
|
+
redirectExpiredAbsent?: String;
|
|
825
|
+
/** The redirect URL to use when the JWT is invalid; invalidity is defined as having a bad
|
|
826
|
+
* signature, or not meeting any specific claim matching criteria which may be specified.
|
|
827
|
+
* Expired/absent tokens are handled separately in {@linkcode redirectExpiredAbsent}. For
|
|
828
|
+
* either case of redirect, you may specify {@linkcode returnUrlParamName} to indicate
|
|
829
|
+
* how the URL redirecting the client should be forwarded; this can be used to send a client
|
|
830
|
+
* to the login page and allow a seamless return.
|
|
831
|
+
*/
|
|
832
|
+
redirectInvalid?: String;
|
|
833
|
+
/** When redirecting to those URLs, then a query/search parameter will be added to the redirect
|
|
834
|
+
* URL with the original URL, for example to allow the login sub system to return the user
|
|
835
|
+
* to the page which triggered the redirect to login
|
|
836
|
+
*/
|
|
837
|
+
returnUrlParamName?: String;
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Options for the `proxy` method
|
|
841
|
+
*/
|
|
842
|
+
export interface ProxyOptions {
|
|
843
|
+
/**
|
|
844
|
+
* Additional headers to send upstream
|
|
845
|
+
*/
|
|
846
|
+
headers?: {
|
|
847
|
+
[key: string]: string;
|
|
848
|
+
};
|
|
849
|
+
/**
|
|
850
|
+
* The path for the URL to request from the upstream site. You can reference variables
|
|
851
|
+
* captured by the route pattern using `:variable`.
|
|
852
|
+
*
|
|
853
|
+
* **Example**
|
|
854
|
+
*
|
|
855
|
+
* ```
|
|
856
|
+
* new Router()
|
|
857
|
+
* .get('/some/path/with/:variable', ({ proxy }) => {
|
|
858
|
+
* proxy('legacy', { path: '/some/other/path/with/:variable' })
|
|
859
|
+
* })
|
|
860
|
+
* ```
|
|
861
|
+
*
|
|
862
|
+
* Path can also be a function that returns a URL path string, in which case it will be computed in the cloud
|
|
863
|
+
* rather than at build time.
|
|
864
|
+
*/
|
|
865
|
+
path?: string | (() => string | undefined);
|
|
866
|
+
/**
|
|
867
|
+
* A function that transforms the request before it is sent to the upstream server. In general, this
|
|
868
|
+
* is used to alter the request headers or body based on some conditional logic. Note that code in
|
|
869
|
+
* this method will be executed at the serverless tier and not the edge.
|
|
870
|
+
*/
|
|
871
|
+
transformRequest?: (request: Request) => void;
|
|
872
|
+
/**
|
|
873
|
+
* A function that transforms the response before it is returned to the browser. This function
|
|
874
|
+
* typically alters `response.body` to change the content sent to the browser. It can also add, remove,
|
|
875
|
+
* and alter response headers. Note that code in this method will be executed at the serverless tier
|
|
876
|
+
* and not the edge.
|
|
877
|
+
*/
|
|
878
|
+
transformResponse?: (response: Response, request: Request) => void;
|
|
879
|
+
/**
|
|
880
|
+
* Removes the "=" from search parameters that have no value. So for example:
|
|
881
|
+
* "http://domain.com?foo=&bar=" becomes "http://domain.com?foo&bar"
|
|
882
|
+
*/
|
|
883
|
+
removeEmptySearchParamValues?: boolean;
|
|
884
|
+
}
|
|
885
|
+
export interface CorsOptions {
|
|
886
|
+
/**
|
|
887
|
+
* Sets the Access-Control-Allow-Origin header.
|
|
888
|
+
*
|
|
889
|
+
* Access-Control-Allow-Origin specifies either a single origin, which tells browsers to allow that origin to access
|
|
890
|
+
* the resource; or else — for requests without credentials — the "*" wildcard, to tell browsers to allow any
|
|
891
|
+
* origin to access the resource. If omitted, "*"" will be used
|
|
892
|
+
*/
|
|
893
|
+
origin?: string;
|
|
894
|
+
/**
|
|
895
|
+
* Sets the Access-Control-Allow-Methods header.
|
|
896
|
+
*
|
|
897
|
+
* The Access-Control-Allow-Methods header specifies the method or methods allowed when accessing the resource. This is used
|
|
898
|
+
* in response to a preflight request. The conditions under which a request is preflighted are discussed above.
|
|
899
|
+
*/
|
|
900
|
+
methods?: string[];
|
|
901
|
+
/**
|
|
902
|
+
* Sets the Access-Control-Allow-Headers header.
|
|
903
|
+
*
|
|
904
|
+
* The Access-Control-Allow-Headers header is used in response to a preflight request to indicate which HTTP headers
|
|
905
|
+
* can be used when making the actual request.
|
|
906
|
+
*/
|
|
907
|
+
headers?: string[];
|
|
908
|
+
/**
|
|
909
|
+
* Sets the Access-Control-Max-Age header.
|
|
910
|
+
*
|
|
911
|
+
* The Access-Control-Max-Age header indicates how long the results of a preflight request can be cached.
|
|
912
|
+
* For an example of a preflight request, see the above examples.
|
|
913
|
+
*/
|
|
914
|
+
maxAge?: number;
|
|
915
|
+
/**
|
|
916
|
+
* Sets the Access-Control-Allow-Credentials header.
|
|
917
|
+
*
|
|
918
|
+
* The Access-Control-Allow-Credentials header Indicates whether or not the response to the request can be exposed
|
|
919
|
+
* when the credentials flag is true. When used as part of a response to a preflight request, this indicates whether
|
|
920
|
+
* or not the actual request can be made using credentials. Note that simple GET requests are not preflighted, and
|
|
921
|
+
* so if a request is made for a resource with credentials, if this header is not returned with the resource, the
|
|
922
|
+
* response is ignored by the browser and not returned to web content.
|
|
923
|
+
*/
|
|
924
|
+
credentials?: boolean;
|
|
925
|
+
}
|
|
926
|
+
export declare type RedirectOptions = {
|
|
927
|
+
/**
|
|
928
|
+
* Query strings to be added to the redirect url.
|
|
929
|
+
*/
|
|
930
|
+
query?: {
|
|
931
|
+
[key: string]: string;
|
|
932
|
+
};
|
|
933
|
+
/**
|
|
934
|
+
* HTTP Response status code for the redirect response
|
|
935
|
+
* Default: 302
|
|
936
|
+
*/
|
|
937
|
+
statusCode?: number;
|
|
938
|
+
} | number;
|
|
939
|
+
/**
|
|
940
|
+
* Options for the `serveStatic` method.
|
|
941
|
+
*/
|
|
942
|
+
export interface ServeStaticOptions {
|
|
943
|
+
/**
|
|
944
|
+
* A function to run when no static asset exists at the specified path. Use this option to
|
|
945
|
+
* perform server-side rendering for URLs that are not statically rendered at build-time.
|
|
946
|
+
*
|
|
947
|
+
* Example:
|
|
948
|
+
*
|
|
949
|
+
* ```js
|
|
950
|
+
* router.get('/products/:id', res => {
|
|
951
|
+
* res.serveStatic('dist/products/:id.html', {
|
|
952
|
+
* onNotFound: () => res.renderWithApp() // fall back to server-side rendering
|
|
953
|
+
* })
|
|
954
|
+
* })
|
|
955
|
+
* ```
|
|
956
|
+
*
|
|
957
|
+
* Because SSR can often be slow, we recommend using this option in conjunction with
|
|
958
|
+
* `loadingPage` so that users do not have to wait for SSR to finish before seeing something in their browser.
|
|
959
|
+
*/
|
|
960
|
+
onNotFound?: (res: ResponseWriter) => Promise<void>;
|
|
961
|
+
/**
|
|
962
|
+
* The path to a statically rendered loading page to be served when falling back to compute. By
|
|
963
|
+
* specifying both `loadingPage` and `onNotFound`, when a request cannot be fulfilled with a static asset,
|
|
964
|
+
* Layer0 will instantly serve a loading page while computing a server-side rendered result for future requests.
|
|
965
|
+
* This ensures that all requests will have a low time-to-first-byte (TTFB) and no user will need to
|
|
966
|
+
* wait for SSR to finish before seeing something in their browser.
|
|
967
|
+
*
|
|
968
|
+
* Example:
|
|
969
|
+
*
|
|
970
|
+
* ```js
|
|
971
|
+
* router.get('/products/:id', res => {
|
|
972
|
+
* res.serveStatic('dist/products/:id.html', {
|
|
973
|
+
* onNotFound: () => res.renderWithApp(), // fall back to server-side rendering
|
|
974
|
+
* loadingPage: 'dist/products/loading.html' // show the loading page while SSR is in progress
|
|
975
|
+
* })
|
|
976
|
+
* })
|
|
977
|
+
* ```
|
|
978
|
+
*
|
|
979
|
+
* Note that it's up to your front-end code to fetch the data to render the full page when the loading page is served.
|
|
980
|
+
* Frameworks like Next.js, for example, do this automatically when you use `getStaticPaths` with `fallback: true`.
|
|
981
|
+
*/
|
|
982
|
+
loadingPage?: string;
|
|
983
|
+
/**
|
|
984
|
+
* The time in seconds that the statically rendered response is considered valid.
|
|
985
|
+
* Must be a positive number. If it's not specified the rendered response never expires.
|
|
986
|
+
*/
|
|
987
|
+
expiresSeconds?: number;
|
|
988
|
+
/**
|
|
989
|
+
* Sets the status code for the response. If not specified, the status code will be 200.
|
|
990
|
+
*/
|
|
991
|
+
statusCode?: number;
|
|
992
|
+
/**
|
|
993
|
+
* Sets the status code for the response. If not specified, the status message will be "OK".
|
|
994
|
+
*/
|
|
995
|
+
statusMessage?: string;
|
|
996
|
+
/**
|
|
997
|
+
* When true, assets are served from a bucket/prefix that remains available across
|
|
998
|
+
* all builds on a given environment.
|
|
999
|
+
*/
|
|
1000
|
+
permanent?: boolean;
|
|
1001
|
+
/**
|
|
1002
|
+
* List of excluded files that should not be served
|
|
1003
|
+
*/
|
|
1004
|
+
exclude?: string[];
|
|
1005
|
+
/**
|
|
1006
|
+
* Set to true to prevent Layer0 from automatically publishing static files. If you enable this flag, you'll
|
|
1007
|
+
* need to use DeploymentBuilder.addStaticAsset(path) for each static file during the build phase.
|
|
1008
|
+
* @private
|
|
1009
|
+
*/
|
|
1010
|
+
disableAutoPublish?: boolean;
|
|
1011
|
+
}
|