@netlify/plugin-nextjs 4.41.3 → 5.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -17
- package/dist/build/cache.js +15 -0
- package/dist/build/content/prerendered.js +16 -0
- package/dist/build/content/server.js +18 -0
- package/dist/build/content/static.js +20 -0
- package/dist/build/functions/edge.js +14 -0
- package/dist/build/functions/server.js +16 -0
- package/dist/build/plugin-context.js +17 -0
- package/dist/esm-chunks/chunk-4AJYXTWN.js +17 -0
- package/dist/esm-chunks/chunk-62KDS27E.js +77 -0
- package/dist/esm-chunks/chunk-AVWFCGVE.js +5536 -0
- package/dist/esm-chunks/chunk-B6QMRLBH.js +255 -0
- package/dist/esm-chunks/chunk-G2VRYWGL.js +107 -0
- package/dist/esm-chunks/chunk-G3GM7JNF.js +92 -0
- package/dist/esm-chunks/chunk-GGHAQM5D.js +28 -0
- package/dist/esm-chunks/chunk-HPGTYMVD.js +113 -0
- package/dist/esm-chunks/chunk-PEBUKFKH.js +89 -0
- package/dist/esm-chunks/chunk-R4NHZWGU.js +32 -0
- package/dist/esm-chunks/chunk-RSKIKBZH.js +44 -0
- package/dist/esm-chunks/chunk-XD5TSLZO.js +85 -0
- package/dist/esm-chunks/chunk-ZBX3SNQG.js +561 -0
- package/dist/index.js +66 -0
- package/dist/run/config.js +18 -0
- package/dist/run/constants.js +15 -0
- package/dist/run/handlers/cache.cjs +849 -0
- package/dist/run/handlers/server.js +3289 -0
- package/dist/run/headers.js +19 -0
- package/dist/run/next.cjs +1055 -0
- package/dist/run/revalidate.js +13 -0
- package/edge-runtime/README.md +29 -0
- package/edge-runtime/lib/headers.ts +26 -0
- package/edge-runtime/lib/middleware.ts +60 -0
- package/edge-runtime/lib/next-request.ts +59 -0
- package/edge-runtime/lib/response.ts +145 -0
- package/edge-runtime/lib/util.ts +26 -0
- package/edge-runtime/middleware.ts +40 -0
- package/edge-runtime/shim/index.js +8 -0
- package/{src/templates → edge-runtime}/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +1 -1
- package/edge-runtime/vendor/import_map.json +13 -0
- package/edge-runtime/vendor.ts +18 -0
- package/manifest.yml +1 -1
- package/package.json +23 -60
- package/index.js +0 -1
- package/lib/constants.js +0 -56
- package/lib/helpers/analysis.js +0 -115
- package/lib/helpers/cache.js +0 -46
- package/lib/helpers/compiler.js +0 -119
- package/lib/helpers/config.js +0 -192
- package/lib/helpers/dev.js +0 -20
- package/lib/helpers/edge.js +0 -328
- package/lib/helpers/files.js +0 -335
- package/lib/helpers/flags.js +0 -46
- package/lib/helpers/functions.js +0 -437
- package/lib/helpers/functionsMetaData.js +0 -46
- package/lib/helpers/matchers.js +0 -41
- package/lib/helpers/middlewareWatcher.js +0 -12
- package/lib/helpers/pack.js +0 -41
- package/lib/helpers/redirects.js +0 -246
- package/lib/helpers/types.js +0 -2
- package/lib/helpers/utils.js +0 -226
- package/lib/helpers/verification.js +0 -182
- package/lib/index.js +0 -194
- package/lib/templates/blobStorage.js +0 -30
- package/lib/templates/getApiHandler.js +0 -120
- package/lib/templates/getHandler.js +0 -201
- package/lib/templates/getPageResolver.js +0 -54
- package/lib/templates/handlerUtils.js +0 -268
- package/lib/templates/ipx.js +0 -13
- package/lib/templates/requireHooks.js +0 -105
- package/lib/templates/server.js +0 -159
- package/lib/templates/vendor.js +0 -20
- package/src/templates/edge/bundle.js +0 -8
- package/src/templates/edge/function-runtime.ts +0 -24
- package/src/templates/edge/imageconfig.json +0 -3
- package/src/templates/edge/ipx.ts +0 -5
- package/src/templates/edge/matchers.json +0 -1
- package/src/templates/edge/middleware-runtime.ts +0 -62
- package/src/templates/edge/next-dev.js +0 -104
- package/src/templates/edge/rsc-data.ts +0 -5
- package/src/templates/edge/shims.js +0 -77
- package/src/templates/edge-shared/next-utils.ts +0 -407
- package/src/templates/edge-shared/nextConfig.json +0 -3
- package/src/templates/edge-shared/prerender-manifest.json +0 -7
- package/src/templates/edge-shared/rsc-data.ts +0 -78
- package/src/templates/edge-shared/utils.test.ts +0 -114
- package/src/templates/edge-shared/utils.ts +0 -315
- package/src/templates/vendor/import_map.json +0 -13
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.134.0/fmt/colors.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.134.0/testing/_diff.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.134.0/testing/asserts.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/_util/asserts.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/_util/os.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/abortable.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/deadline.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/debounce.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/deferred.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/delay.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/mod.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/mux_async_iterator.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/pool.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/retry.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/tee.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/bytes/index_of_needle.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/crypto/timing_safe_equal.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/datetime/to_imf.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/encoding/base64.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/encoding/base64url.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/flags/mod.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/fmt/colors.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/fmt/printf.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/http/cookie.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_core.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_events.d.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_events.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_global.d.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_next_tick.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_process/exiting.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_process/process.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_process/stdio.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_process/streams.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_stream.d.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_stream.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_util/_util_callbackify.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_utils.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/assert.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/assertion_error.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/async_hooks.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/buffer.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/events.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/buffer.d.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/buffer.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/crypto/_keys.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/crypto/constants.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/error_codes.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/errors.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/fixed_queue.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/hide_stack_frames.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/net.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/normalize_encoding.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/options.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/primordials.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/process/per_thread.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/readline/callbacks.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/readline/utils.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/streams/destroy.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/streams/end-of-stream.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/streams/utils.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util/comparisons.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util/debuglog.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util/inspect.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util/types.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/validators.mjs +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_libuv_winerror.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_listen.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_node.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_timingSafeEqual.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_utils.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_winerror.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/ares.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/async_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/buffer.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/cares_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/config.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/connection_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/constants.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/contextify.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/credentials.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/crypto.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/errors.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/fs.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/fs_dir.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/fs_event_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/handle_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/heap_utils.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/http_parser.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/icu.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/inspector.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/js_stream.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/messaging.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/mod.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/module_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/native_module.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/natives.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/node_file.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/node_options.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/options.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/os.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/performance.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/pipe_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/process_methods.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/report.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/serdes.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/signal_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/spawn_sync.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/stream_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/string_decoder.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/symbols.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/task_queue.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/tcp_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/timers.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/tls_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/trace_events.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/tty_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/types.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/udp_wrap.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/url.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/util.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/uv.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/v8.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/worker.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/zlib.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/process.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/stream.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/string_decoder.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/util/types.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/util.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/_constants.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/_interface.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/_util.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/common.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/glob.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/mod.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/posix.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/separator.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/win32.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/streams/write_all.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/testing/_diff.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/testing/_format.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/testing/asserts.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/types.d.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +0 -0
- /package/{src/templates → edge-runtime}/vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts +0 -0
- /package/{src/templates → edge-runtime}/vendor/esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js +0 -0
- /package/{src/templates → edge-runtime}/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js +0 -0
- /package/{src/templates → edge-runtime}/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js +0 -0
- /package/{src/templates → edge-runtime}/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +0 -0
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { Context } from 'https://edge.netlify.com'
|
|
2
|
-
// Available at build time
|
|
3
|
-
import matchers from './matchers.json' assert { type: 'json' }
|
|
4
|
-
import edgeFunction from './bundle.js'
|
|
5
|
-
import { buildNextRequest, buildResponse } from '../edge-shared/utils.ts'
|
|
6
|
-
import { getMiddlewareRouteMatcher, MiddlewareRouteMatch, searchParamsToUrlQuery } from '../edge-shared/next-utils.ts'
|
|
7
|
-
import nextConfig from '../edge-shared/nextConfig.json' assert { type: 'json' }
|
|
8
|
-
|
|
9
|
-
const matchesMiddleware: MiddlewareRouteMatch = getMiddlewareRouteMatcher(matchers || [])
|
|
10
|
-
|
|
11
|
-
export interface RequestContext {
|
|
12
|
-
request: Request
|
|
13
|
-
context: Context
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
declare global {
|
|
17
|
-
// deno-lint-ignore no-var
|
|
18
|
-
var NFRequestContextMap: Map<string, RequestContext>
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
globalThis.NFRequestContextMap ||= new Map()
|
|
22
|
-
|
|
23
|
-
const handler = async (req: Request, context: Context) => {
|
|
24
|
-
if (Deno.env.get('NETLIFY_DEV')) {
|
|
25
|
-
// Don't run in dev
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const url = new URL(req.url)
|
|
30
|
-
|
|
31
|
-
// While we have already checked the path when mapping to the edge function,
|
|
32
|
-
// Next.js supports extra rules that we need to check here too.
|
|
33
|
-
if (!matchesMiddleware(url.pathname, req, searchParamsToUrlQuery(url.searchParams))) {
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const requestId = req.headers.get('x-nf-request-id')
|
|
38
|
-
if (!requestId) {
|
|
39
|
-
console.error('Missing x-nf-request-id header')
|
|
40
|
-
} else {
|
|
41
|
-
globalThis.NFRequestContextMap.set(requestId, {
|
|
42
|
-
request: req,
|
|
43
|
-
context,
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const request = buildNextRequest(req, context, nextConfig)
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
const result = await edgeFunction({ request })
|
|
51
|
-
return buildResponse({ result, request: req, context })
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error(error)
|
|
54
|
-
return new Response(error.message, { status: 500 })
|
|
55
|
-
} finally {
|
|
56
|
-
if (requestId) {
|
|
57
|
-
globalThis.NFRequestContextMap.delete(requestId)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export default handler
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { NextRequest } from '../vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js'
|
|
2
|
-
import { NextResponse } from '../vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js'
|
|
3
|
-
import { fromFileUrl } from '../vendor/deno.land/std@0.175.0/path/mod.ts'
|
|
4
|
-
import { buildResponse, isFunction } from '../edge-shared/utils.ts'
|
|
5
|
-
|
|
6
|
-
globalThis.NFRequestContextMap ||= new Map()
|
|
7
|
-
globalThis.__dirname = fromFileUrl(new URL('./', import.meta.url)).slice(0, -1)
|
|
8
|
-
globalThis.process ||= { env: Deno.env.toObject() }
|
|
9
|
-
|
|
10
|
-
// Next.js uses this extension to the Headers API implemented by Cloudflare workerd
|
|
11
|
-
if (!('getAll' in Headers.prototype)) {
|
|
12
|
-
Headers.prototype.getAll = function getAll(name) {
|
|
13
|
-
name = name.toLowerCase()
|
|
14
|
-
if (name !== 'set-cookie') {
|
|
15
|
-
throw new Error('Headers.getAll is only supported for Set-Cookie')
|
|
16
|
-
}
|
|
17
|
-
return [...this.entries()].filter(([key]) => key === name).map(([, value]) => value)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let idx = 0
|
|
22
|
-
|
|
23
|
-
const handler = async (req, context) => {
|
|
24
|
-
if (!Deno.env.get('NETLIFY_DEV')) {
|
|
25
|
-
// Only run in dev
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let middleware
|
|
30
|
-
// Dynamic imports and FS operations aren't allowed when deployed,
|
|
31
|
-
// but that's fine because this is only ever used locally.
|
|
32
|
-
// We don't want to just try importing and use that to test,
|
|
33
|
-
// because that would also throw if there's an error in the middleware,
|
|
34
|
-
// which we would want to surface not ignore.
|
|
35
|
-
try {
|
|
36
|
-
// We need to cache-bust the import because otherwise it will claim it
|
|
37
|
-
// doesn't exist if the user creates it after the server starts
|
|
38
|
-
const nextMiddleware = await import(`../../middleware.js#${++idx}`)
|
|
39
|
-
|
|
40
|
-
// The middleware file can export a named `middleware` export or a `default` export
|
|
41
|
-
middleware = isFunction(nextMiddleware.middleware)
|
|
42
|
-
? nextMiddleware.middleware
|
|
43
|
-
: isFunction(nextMiddleware.default)
|
|
44
|
-
? nextMiddleware.default
|
|
45
|
-
: undefined
|
|
46
|
-
|
|
47
|
-
if (!middleware) {
|
|
48
|
-
throw new Error('The middleware must export a `middleware` or a `default` function')
|
|
49
|
-
}
|
|
50
|
-
} catch (importError) {
|
|
51
|
-
if (importError.code === 'ERR_MODULE_NOT_FOUND' && importError.message.includes(`middleware.js`)) {
|
|
52
|
-
// No middleware, so we silently return
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
throw importError
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// This is the format expected by Next.js along with the timezone which we support.
|
|
60
|
-
const geo = {
|
|
61
|
-
country: context.geo.country?.code,
|
|
62
|
-
region: context.geo.subdivision?.code,
|
|
63
|
-
city: context.geo.city,
|
|
64
|
-
latitude: context.geo.latitude?.toString(),
|
|
65
|
-
longitude: context.geo.longitude?.toString(),
|
|
66
|
-
timezone: context.geo.timezone,
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// A default request id is fine locally
|
|
70
|
-
const requestId = req.headers.get('x-nf-request-id') || 'request-id'
|
|
71
|
-
|
|
72
|
-
globalThis.NFRequestContextMap.set(requestId, {
|
|
73
|
-
request: req,
|
|
74
|
-
context,
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
const request = {
|
|
78
|
-
headers: Object.fromEntries(req.headers.entries()),
|
|
79
|
-
geo,
|
|
80
|
-
method: req.method,
|
|
81
|
-
ip: context.ip,
|
|
82
|
-
body: req.body || undefined,
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const nextRequest = new NextRequest(req, request)
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
const response = await middleware(nextRequest)
|
|
89
|
-
return buildResponse({
|
|
90
|
-
result: { response: response || NextResponse.next(), waitUntil: Promise.resolve() },
|
|
91
|
-
request: req,
|
|
92
|
-
context,
|
|
93
|
-
})
|
|
94
|
-
} catch (error) {
|
|
95
|
-
console.error(error)
|
|
96
|
-
return new Response(error.message, { status: 500 })
|
|
97
|
-
} finally {
|
|
98
|
-
if (requestId) {
|
|
99
|
-
globalThis.NFRequestContextMap.delete(requestId)
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export default handler
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import prerenderManifest from '../edge-shared/prerender-manifest.json' assert { type: 'json' }
|
|
2
|
-
import { getRscDataRouter, PrerenderManifest } from '../edge-shared/rsc-data.ts'
|
|
3
|
-
|
|
4
|
-
const handler = getRscDataRouter(prerenderManifest as PrerenderManifest)
|
|
5
|
-
export default handler
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
// deno-lint-ignore-file prefer-const no-unused-vars
|
|
3
|
-
import { decode as _base64Decode } from '../vendor/deno.land/std@0.175.0/encoding/base64.ts'
|
|
4
|
-
import BufferCompat from '../vendor/deno.land/std@0.175.0/node/buffer.ts'
|
|
5
|
-
import EventsCompat from '../vendor/deno.land/std@0.175.0/node/events.ts'
|
|
6
|
-
import AsyncHooksCompat from '../vendor/deno.land/std@0.175.0/node/async_hooks.ts'
|
|
7
|
-
import AssertCompat from '../vendor/deno.land/std@0.175.0/node/assert.ts'
|
|
8
|
-
import UtilCompat from '../vendor/deno.land/std@0.175.0/node/util.ts'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* These are the shims, polyfills and other kludges to make Next.js work in standards-compliant runtime.
|
|
12
|
-
* This file isn't imported, but is instead inlined along with other chunks into the edge bundle.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
// Deno defines "window", but naughty libraries think this means it's a browser
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
delete globalThis.window
|
|
18
|
-
globalThis.process = {
|
|
19
|
-
env: { ...Deno.env.toObject(), NEXT_RUNTIME: 'edge', NEXT_PRIVATE_MINIMAL_MODE: '1' },
|
|
20
|
-
}
|
|
21
|
-
globalThis.EdgeRuntime = 'netlify-edge'
|
|
22
|
-
let _ENTRIES = {}
|
|
23
|
-
|
|
24
|
-
// Next.js expects this as a global
|
|
25
|
-
globalThis.AsyncLocalStorage = AsyncHooksCompat.AsyncLocalStorage
|
|
26
|
-
|
|
27
|
-
// Next.js uses this extension to the Headers API implemented by Cloudflare workerd
|
|
28
|
-
if (!('getAll' in Headers.prototype)) {
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
Headers.prototype.getAll = function getAll(name) {
|
|
31
|
-
name = name.toLowerCase()
|
|
32
|
-
if (name !== 'set-cookie') {
|
|
33
|
-
throw new Error('Headers.getAll is only supported for Set-Cookie')
|
|
34
|
-
}
|
|
35
|
-
return [...this.entries()].filter(([key]) => key === name).map(([, value]) => value)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
// Next uses blob: urls to refer to local assets, so we need to intercept these
|
|
39
|
-
const _fetch = globalThis.fetch
|
|
40
|
-
const fetch /* type {typeof globalThis.fetch} */ = async (url, init) => {
|
|
41
|
-
try {
|
|
42
|
-
if (url instanceof URL && url.href?.startsWith('blob:')) {
|
|
43
|
-
const key = url.href.slice(5)
|
|
44
|
-
if (key in _ASSETS) {
|
|
45
|
-
return new Response(_base64Decode(_ASSETS[key]))
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return await _fetch(url, init)
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.error(error)
|
|
51
|
-
throw error
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Shim native modules that Vercel makes available
|
|
56
|
-
if (typeof require === 'undefined') {
|
|
57
|
-
globalThis.require = (name) => {
|
|
58
|
-
switch (name.replace(/^node:/, '')) {
|
|
59
|
-
case 'buffer':
|
|
60
|
-
return BufferCompat
|
|
61
|
-
case 'events':
|
|
62
|
-
return EventsCompat
|
|
63
|
-
case 'async_hooks':
|
|
64
|
-
return AsyncHooksCompat
|
|
65
|
-
case 'assert':
|
|
66
|
-
return AssertCompat
|
|
67
|
-
case 'util':
|
|
68
|
-
return UtilCompat
|
|
69
|
-
default:
|
|
70
|
-
throw new ReferenceError(`Native module not found: ${name}`)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Next edge runtime uses "self" as a function-scoped global-like object, but some of the older polyfills expect it to equal globalThis
|
|
76
|
-
// See https://nextjs.org/docs/basic-features/supported-browsers-features#polyfills
|
|
77
|
-
const self = { ...globalThis, fetch }
|
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Various router utils ported to Deno from Next.js source
|
|
3
|
-
* https://github.com/vercel/next.js/blob/7280c3ced186bb9a7ae3d7012613ef93f20b0fa9/packages/next/shared/lib/router/utils/
|
|
4
|
-
* Licence: https://github.com/vercel/next.js/blob/7280c3ced186bb9a7ae3d7012613ef93f20b0fa9/license.md
|
|
5
|
-
*
|
|
6
|
-
* Some types have been re-implemented to be more compatible with Deno or avoid chains of dependent files
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Deno imports
|
|
10
|
-
import type { Key } from '../vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts'
|
|
11
|
-
|
|
12
|
-
import { compile, pathToRegexp } from '../vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts'
|
|
13
|
-
import { getCookies } from '../vendor/deno.land/std@0.175.0/http/cookie.ts'
|
|
14
|
-
|
|
15
|
-
// Inlined/re-implemented types
|
|
16
|
-
|
|
17
|
-
export interface ParsedUrlQuery {
|
|
18
|
-
[key: string]: string | string[]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface Params {
|
|
22
|
-
// Yeah, best we get
|
|
23
|
-
// deno-lint-ignore no-explicit-any
|
|
24
|
-
[param: string]: any
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type RouteHas =
|
|
28
|
-
| {
|
|
29
|
-
type: 'header' | 'query' | 'cookie'
|
|
30
|
-
key: string
|
|
31
|
-
value?: string
|
|
32
|
-
}
|
|
33
|
-
| {
|
|
34
|
-
type: 'host'
|
|
35
|
-
key?: undefined
|
|
36
|
-
value: string
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type Rewrite = {
|
|
40
|
-
source: string
|
|
41
|
-
destination: string
|
|
42
|
-
basePath?: false
|
|
43
|
-
locale?: false
|
|
44
|
-
has?: RouteHas[]
|
|
45
|
-
missing?: RouteHas[]
|
|
46
|
-
regex: string
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type Header = {
|
|
50
|
-
source: string
|
|
51
|
-
basePath?: false
|
|
52
|
-
locale?: false
|
|
53
|
-
headers: Array<{ key: string; value: string }>
|
|
54
|
-
has?: RouteHas[]
|
|
55
|
-
missing?: RouteHas[]
|
|
56
|
-
regex: string
|
|
57
|
-
}
|
|
58
|
-
export type Redirect = {
|
|
59
|
-
source: string
|
|
60
|
-
destination: string
|
|
61
|
-
basePath?: false
|
|
62
|
-
locale?: false
|
|
63
|
-
has?: RouteHas[]
|
|
64
|
-
missing?: RouteHas[]
|
|
65
|
-
statusCode?: number
|
|
66
|
-
permanent?: boolean
|
|
67
|
-
regex: string
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export type DynamicRoute = {
|
|
71
|
-
page: string
|
|
72
|
-
regex: string
|
|
73
|
-
namedRegex?: string
|
|
74
|
-
routeKeys?: { [key: string]: string }
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export type RoutesManifest = {
|
|
78
|
-
basePath: string
|
|
79
|
-
redirects: Redirect[]
|
|
80
|
-
headers: Header[]
|
|
81
|
-
rewrites: {
|
|
82
|
-
beforeFiles: Rewrite[]
|
|
83
|
-
afterFiles: Rewrite[]
|
|
84
|
-
fallback: Rewrite[]
|
|
85
|
-
}
|
|
86
|
-
dynamicRoutes: DynamicRoute[]
|
|
87
|
-
}
|
|
88
|
-
// escape-regexp.ts
|
|
89
|
-
// regexp is based on https://github.com/sindresorhus/escape-string-regexp
|
|
90
|
-
const reHasRegExp = /[|\\{}()[\]^$+*?.-]/
|
|
91
|
-
const reReplaceRegExp = /[|\\{}()[\]^$+*?.-]/g
|
|
92
|
-
|
|
93
|
-
export function escapeStringRegexp(str: string) {
|
|
94
|
-
// see also: https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/escapeRegExp.js#L23
|
|
95
|
-
if (reHasRegExp.test(str)) {
|
|
96
|
-
return str.replace(reReplaceRegExp, '\\$&')
|
|
97
|
-
}
|
|
98
|
-
return str
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// querystring.ts
|
|
102
|
-
export function searchParamsToUrlQuery(searchParams: URLSearchParams): ParsedUrlQuery {
|
|
103
|
-
const query: ParsedUrlQuery = {}
|
|
104
|
-
searchParams.forEach((value, key) => {
|
|
105
|
-
if (typeof query[key] === 'undefined') {
|
|
106
|
-
query[key] = value
|
|
107
|
-
} else if (Array.isArray(query[key])) {
|
|
108
|
-
;(query[key] as string[]).push(value)
|
|
109
|
-
} else {
|
|
110
|
-
query[key] = [query[key] as string, value]
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
return query
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// parse-url.ts
|
|
117
|
-
interface ParsedUrl {
|
|
118
|
-
hash: string
|
|
119
|
-
hostname?: string | null
|
|
120
|
-
href: string
|
|
121
|
-
pathname: string
|
|
122
|
-
port?: string | null
|
|
123
|
-
protocol?: string | null
|
|
124
|
-
query: ParsedUrlQuery
|
|
125
|
-
search: string
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function parseUrl(url: string): ParsedUrl {
|
|
129
|
-
const parsedURL = url.startsWith('/') ? new URL(url, 'http://n') : new URL(url)
|
|
130
|
-
return {
|
|
131
|
-
hash: parsedURL.hash,
|
|
132
|
-
hostname: parsedURL.hostname,
|
|
133
|
-
href: parsedURL.href,
|
|
134
|
-
pathname: parsedURL.pathname,
|
|
135
|
-
port: parsedURL.port,
|
|
136
|
-
protocol: parsedURL.protocol,
|
|
137
|
-
query: searchParamsToUrlQuery(parsedURL.searchParams),
|
|
138
|
-
search: parsedURL.search,
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// prepare-destination.ts
|
|
143
|
-
// Changed to use WHATWG Fetch Request instead of IncomingMessage
|
|
144
|
-
export function matchHas(
|
|
145
|
-
req: Pick<Request, 'headers' | 'url'>,
|
|
146
|
-
query: Params,
|
|
147
|
-
has: RouteHas[] = [],
|
|
148
|
-
missing: RouteHas[] = [],
|
|
149
|
-
): false | Params {
|
|
150
|
-
const params: Params = {}
|
|
151
|
-
const cookies = getCookies(req.headers)
|
|
152
|
-
const url = new URL(req.url)
|
|
153
|
-
const hasMatch = (hasItem: RouteHas) => {
|
|
154
|
-
let value: undefined | string | null
|
|
155
|
-
let key = hasItem.key
|
|
156
|
-
|
|
157
|
-
switch (hasItem.type) {
|
|
158
|
-
case 'header': {
|
|
159
|
-
key = hasItem.key.toLowerCase()
|
|
160
|
-
value = req.headers.get(key)
|
|
161
|
-
break
|
|
162
|
-
}
|
|
163
|
-
case 'cookie': {
|
|
164
|
-
value = cookies[hasItem.key]
|
|
165
|
-
break
|
|
166
|
-
}
|
|
167
|
-
case 'query': {
|
|
168
|
-
value = query[hasItem.key]
|
|
169
|
-
break
|
|
170
|
-
}
|
|
171
|
-
case 'host': {
|
|
172
|
-
value = url.hostname
|
|
173
|
-
break
|
|
174
|
-
}
|
|
175
|
-
default: {
|
|
176
|
-
break
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (!hasItem.value && value && key) {
|
|
180
|
-
params[getSafeParamName(key)] = value
|
|
181
|
-
return true
|
|
182
|
-
} else if (value) {
|
|
183
|
-
const matcher = new RegExp(`^${hasItem.value}$`)
|
|
184
|
-
const matches = Array.isArray(value) ? value.slice(-1)[0].match(matcher) : value.match(matcher)
|
|
185
|
-
|
|
186
|
-
if (matches) {
|
|
187
|
-
if (Array.isArray(matches)) {
|
|
188
|
-
if (matches.groups) {
|
|
189
|
-
Object.keys(matches.groups).forEach((groupKey) => {
|
|
190
|
-
params[groupKey] = matches.groups![groupKey]
|
|
191
|
-
})
|
|
192
|
-
} else if (hasItem.type === 'host' && matches[0]) {
|
|
193
|
-
params.host = matches[0]
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return true
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return false
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const allMatch = has.every((item) => hasMatch(item)) && !missing.some((item) => hasMatch(item))
|
|
203
|
-
|
|
204
|
-
if (allMatch) {
|
|
205
|
-
return params
|
|
206
|
-
}
|
|
207
|
-
return false
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export function compileNonPath(value: string, params: Params): string {
|
|
211
|
-
if (!value.includes(':')) {
|
|
212
|
-
return value
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
for (const key of Object.keys(params)) {
|
|
216
|
-
if (value.includes(`:${key}`)) {
|
|
217
|
-
value = value
|
|
218
|
-
.replace(new RegExp(`:${key}\\*`, 'g'), `:${key}--ESCAPED_PARAM_ASTERISKS`)
|
|
219
|
-
.replace(new RegExp(`:${key}\\?`, 'g'), `:${key}--ESCAPED_PARAM_QUESTION`)
|
|
220
|
-
.replace(new RegExp(`:${key}\\+`, 'g'), `:${key}--ESCAPED_PARAM_PLUS`)
|
|
221
|
-
.replace(new RegExp(`:${key}(?!\\w)`, 'g'), `--ESCAPED_PARAM_COLON${key}`)
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
value = value
|
|
225
|
-
.replace(/(:|\*|\?|\+|\(|\)|\{|\})/g, '\\$1')
|
|
226
|
-
.replace(/--ESCAPED_PARAM_PLUS/g, '+')
|
|
227
|
-
.replace(/--ESCAPED_PARAM_COLON/g, ':')
|
|
228
|
-
.replace(/--ESCAPED_PARAM_QUESTION/g, '?')
|
|
229
|
-
.replace(/--ESCAPED_PARAM_ASTERISKS/g, '*')
|
|
230
|
-
// the value needs to start with a forward-slash to be compiled
|
|
231
|
-
// correctly
|
|
232
|
-
return compile(`/${value}`, { validate: false })(params).slice(1)
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export function prepareDestination(args: {
|
|
236
|
-
appendParamsToQuery: boolean
|
|
237
|
-
destination: string
|
|
238
|
-
params: Params
|
|
239
|
-
query: ParsedUrlQuery
|
|
240
|
-
}) {
|
|
241
|
-
const query = Object.assign({}, args.query)
|
|
242
|
-
delete query.__nextLocale
|
|
243
|
-
delete query.__nextDefaultLocale
|
|
244
|
-
delete query.__nextDataReq
|
|
245
|
-
|
|
246
|
-
let escapedDestination = args.destination
|
|
247
|
-
|
|
248
|
-
for (const param of Object.keys({ ...args.params, ...query })) {
|
|
249
|
-
escapedDestination = escapeSegment(escapedDestination, param)
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const parsedDestination: ParsedUrl = parseUrl(escapedDestination)
|
|
253
|
-
const destQuery = parsedDestination.query
|
|
254
|
-
const destPath = unescapeSegments(`${parsedDestination.pathname!}${parsedDestination.hash || ''}`)
|
|
255
|
-
const destHostname = unescapeSegments(parsedDestination.hostname || '')
|
|
256
|
-
const destPathParamKeys: Key[] = []
|
|
257
|
-
const destHostnameParamKeys: Key[] = []
|
|
258
|
-
pathToRegexp(destPath, destPathParamKeys)
|
|
259
|
-
pathToRegexp(destHostname, destHostnameParamKeys)
|
|
260
|
-
|
|
261
|
-
const destParams: (string | number)[] = []
|
|
262
|
-
|
|
263
|
-
destPathParamKeys.forEach((key) => destParams.push(key.name))
|
|
264
|
-
destHostnameParamKeys.forEach((key) => destParams.push(key.name))
|
|
265
|
-
|
|
266
|
-
const destPathCompiler = compile(
|
|
267
|
-
destPath,
|
|
268
|
-
// we don't validate while compiling the destination since we should
|
|
269
|
-
// have already validated before we got to this point and validating
|
|
270
|
-
// breaks compiling destinations with named pattern params from the source
|
|
271
|
-
// e.g. /something:hello(.*) -> /another/:hello is broken with validation
|
|
272
|
-
// since compile validation is meant for reversing and not for inserting
|
|
273
|
-
// params from a separate path-regex into another
|
|
274
|
-
{ validate: false },
|
|
275
|
-
)
|
|
276
|
-
|
|
277
|
-
const destHostnameCompiler = compile(destHostname, { validate: false })
|
|
278
|
-
|
|
279
|
-
// update any params in query values
|
|
280
|
-
for (const [key, strOrArray] of Object.entries(destQuery)) {
|
|
281
|
-
// the value needs to start with a forward-slash to be compiled
|
|
282
|
-
// correctly
|
|
283
|
-
if (Array.isArray(strOrArray)) {
|
|
284
|
-
destQuery[key] = strOrArray.map((value) => compileNonPath(unescapeSegments(value), args.params))
|
|
285
|
-
} else {
|
|
286
|
-
destQuery[key] = compileNonPath(unescapeSegments(strOrArray), args.params)
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// add path params to query if it's not a redirect and not
|
|
291
|
-
// already defined in destination query or path
|
|
292
|
-
const paramKeys = Object.keys(args.params).filter((name) => name !== 'nextInternalLocale')
|
|
293
|
-
|
|
294
|
-
if (args.appendParamsToQuery && !paramKeys.some((key) => destParams.includes(key))) {
|
|
295
|
-
for (const key of paramKeys) {
|
|
296
|
-
if (!(key in destQuery)) {
|
|
297
|
-
destQuery[key] = args.params[key]
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
let newUrl
|
|
303
|
-
|
|
304
|
-
try {
|
|
305
|
-
newUrl = destPathCompiler(args.params)
|
|
306
|
-
|
|
307
|
-
const [pathname, hash] = newUrl.split('#')
|
|
308
|
-
parsedDestination.hostname = destHostnameCompiler(args.params)
|
|
309
|
-
parsedDestination.pathname = pathname
|
|
310
|
-
parsedDestination.hash = `${hash ? '#' : ''}${hash || ''}`
|
|
311
|
-
delete (parsedDestination as any).search
|
|
312
|
-
} catch (err: any) {
|
|
313
|
-
if (err.message.match(/Expected .*? to not repeat, but got an array/)) {
|
|
314
|
-
throw new Error(
|
|
315
|
-
`To use a multi-match in the destination you must add \`*\` at the end of the param name to signify it should repeat. https://nextjs.org/docs/messages/invalid-multi-match`,
|
|
316
|
-
)
|
|
317
|
-
}
|
|
318
|
-
throw err
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Query merge order lowest priority to highest
|
|
322
|
-
// 1. initial URL query values
|
|
323
|
-
// 2. path segment values
|
|
324
|
-
// 3. destination specified query values
|
|
325
|
-
parsedDestination.query = {
|
|
326
|
-
...query,
|
|
327
|
-
...parsedDestination.query,
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
return {
|
|
331
|
-
newUrl,
|
|
332
|
-
destQuery,
|
|
333
|
-
parsedDestination,
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Ensure only a-zA-Z are used for param names for proper interpolating
|
|
339
|
-
* with path-to-regexp
|
|
340
|
-
*/
|
|
341
|
-
function getSafeParamName(paramName: string) {
|
|
342
|
-
let newParamName = ''
|
|
343
|
-
|
|
344
|
-
for (let i = 0; i < paramName.length; i++) {
|
|
345
|
-
const charCode = paramName.charCodeAt(i)
|
|
346
|
-
|
|
347
|
-
if (
|
|
348
|
-
(charCode > 64 && charCode < 91) || // A-Z
|
|
349
|
-
(charCode > 96 && charCode < 123) // a-z
|
|
350
|
-
) {
|
|
351
|
-
newParamName += paramName[i]
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
return newParamName
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
function escapeSegment(str: string, segmentName: string) {
|
|
358
|
-
return str.replace(new RegExp(`:${escapeStringRegexp(segmentName)}`, 'g'), `__ESC_COLON_${segmentName}`)
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
function unescapeSegments(str: string) {
|
|
362
|
-
return str.replace(/__ESC_COLON_/gi, ':')
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// is-dynamic.ts
|
|
366
|
-
// Identify /[param]/ in route string
|
|
367
|
-
const TEST_ROUTE = /\/\[[^/]+?\](?=\/|$)/
|
|
368
|
-
|
|
369
|
-
export function isDynamicRoute(route: string): boolean {
|
|
370
|
-
return TEST_ROUTE.test(route)
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// packages/next/shared/lib/router/utils/middleware-route-matcher.ts
|
|
374
|
-
// 12.3 middleware route matcher
|
|
375
|
-
|
|
376
|
-
export interface MiddlewareRouteMatch {
|
|
377
|
-
(pathname: string | null | undefined, request: Pick<Request, 'headers' | 'url'>, query: Params): boolean
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
export interface MiddlewareMatcher {
|
|
381
|
-
regexp: string
|
|
382
|
-
locale?: false
|
|
383
|
-
has?: RouteHas[]
|
|
384
|
-
missing?: RouteHas[]
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
export function getMiddlewareRouteMatcher(matchers: MiddlewareMatcher[]): MiddlewareRouteMatch {
|
|
388
|
-
return (pathname: string | null | undefined, req: Pick<Request, 'headers' | 'url'>, query: Params) => {
|
|
389
|
-
for (const matcher of matchers) {
|
|
390
|
-
const routeMatch = new RegExp(matcher.regexp).exec(pathname!)
|
|
391
|
-
if (!routeMatch) {
|
|
392
|
-
continue
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (matcher.has || matcher.missing) {
|
|
396
|
-
const hasParams = matchHas(req, query, matcher.has, matcher.missing)
|
|
397
|
-
if (!hasParams) {
|
|
398
|
-
continue
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
return true
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
return false
|
|
406
|
-
}
|
|
407
|
-
}
|