utils.d.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /// <reference types="node" />
  2. import type { IncomingMessage, ServerResponse } from 'http';
  3. import type { Rewrite } from '../../../../lib/load-custom-routes';
  4. import type { BuildManifest } from '../../../../server/get-page-files';
  5. import type { RouteMatch } from '../../../../shared/lib/router/utils/route-matcher';
  6. import type { NextConfig } from '../../../../server/config';
  7. import type { GetServerSideProps, GetStaticPaths, GetStaticProps } from '../../../../types';
  8. import type { BaseNextRequest } from '../../../../server/base-http';
  9. import type { __ApiPreviewProps } from '../../../../server/api-utils';
  10. import { UrlWithParsedQuery } from 'url';
  11. import { ParsedUrlQuery } from 'querystring';
  12. import { getNamedRouteRegex } from '../../../../shared/lib/router/utils/route-regex';
  13. export declare const vercelHeader = "x-vercel-id";
  14. export declare type ServerlessHandlerCtx = {
  15. page: string;
  16. pageModule: any;
  17. pageComponent?: any;
  18. pageConfig?: any;
  19. pageGetStaticProps?: GetStaticProps;
  20. pageGetStaticPaths?: GetStaticPaths;
  21. pageGetServerSideProps?: GetServerSideProps;
  22. appModule?: any;
  23. errorModule?: any;
  24. documentModule?: any;
  25. notFoundModule?: any;
  26. runtimeConfig: any;
  27. buildManifest?: BuildManifest;
  28. reactLoadableManifest?: any;
  29. basePath: string;
  30. rewrites: {
  31. fallback?: Rewrite[];
  32. afterFiles?: Rewrite[];
  33. beforeFiles?: Rewrite[];
  34. };
  35. pageIsDynamic: boolean;
  36. generateEtags: boolean;
  37. distDir: string;
  38. buildId: string;
  39. escapedBuildId: string;
  40. assetPrefix: string;
  41. poweredByHeader: boolean;
  42. canonicalBase: string;
  43. encodedPreviewProps: __ApiPreviewProps;
  44. i18n?: NextConfig['i18n'];
  45. };
  46. export declare function interpolateDynamicPath(pathname: string, params: ParsedUrlQuery, defaultRouteRegex?: ReturnType<typeof getNamedRouteRegex> | undefined): string;
  47. export declare function getUtils({ page, i18n, basePath, rewrites, pageIsDynamic, trailingSlash, }: {
  48. page: ServerlessHandlerCtx['page'];
  49. i18n?: ServerlessHandlerCtx['i18n'];
  50. basePath: ServerlessHandlerCtx['basePath'];
  51. rewrites: ServerlessHandlerCtx['rewrites'];
  52. pageIsDynamic: ServerlessHandlerCtx['pageIsDynamic'];
  53. trailingSlash?: boolean;
  54. }): {
  55. handleLocale: (req: IncomingMessage, res: ServerResponse, parsedUrl: UrlWithParsedQuery, routeNoAssetPath: string, shouldNotRedirect: boolean) => {
  56. defaultLocale: string;
  57. detectedLocale: string;
  58. routeNoAssetPath: string;
  59. } | undefined;
  60. handleRewrites: (req: BaseNextRequest | IncomingMessage, parsedUrl: UrlWithParsedQuery) => {};
  61. handleBasePath: (req: BaseNextRequest | IncomingMessage, parsedUrl: UrlWithParsedQuery) => void;
  62. defaultRouteRegex: {
  63. namedRegex: string;
  64. routeKeys: {
  65. [named: string]: string;
  66. };
  67. groups: {
  68. [groupName: string]: import("../../../../shared/lib/router/utils/route-regex").Group;
  69. };
  70. re: RegExp;
  71. } | undefined;
  72. normalizeVercelUrl: (req: BaseNextRequest | IncomingMessage, trustQuery: boolean, paramKeys?: string[]) => void;
  73. dynamicRouteMatcher: RouteMatch | undefined;
  74. defaultRouteMatches: ParsedUrlQuery | undefined;
  75. getParamsFromRouteMatches: (req: BaseNextRequest | IncomingMessage, renderOpts?: any, detectedLocale?: string) => ParsedUrlQuery;
  76. normalizeDynamicRouteParams: (params: ParsedUrlQuery, ignoreOptional?: boolean) => {
  77. params: ParsedUrlQuery;
  78. hasValidParams: boolean;
  79. };
  80. interpolateDynamicPath: (pathname: string, params: Record<string, string | string[]>) => string;
  81. };