Unverified Commit 0d5baf2c authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Mark this.router protected (#23573)

* Mark this.router protected

Seems that some people (#23558) are using Next.js internals based on the typings that TS generates automatically even though these values are not documented / should not be used in applications. This ensures the router value on Server is not used by accident.

* Mark all variables as protected

https://github.com/vercel/next.js/issues/23349

* fix type error
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 68fc4dea
...@@ -8,6 +8,7 @@ import isAnimated from 'next/dist/compiled/is-animated' ...@@ -8,6 +8,7 @@ import isAnimated from 'next/dist/compiled/is-animated'
import { join } from 'path' import { join } from 'path'
import Stream from 'stream' import Stream from 'stream'
import nodeUrl, { UrlWithParsedQuery } from 'url' import nodeUrl, { UrlWithParsedQuery } from 'url'
import { NextConfig } from '../../next-server/server/config-shared'
import { fileExists } from '../../lib/file-exists' import { fileExists } from '../../lib/file-exists'
import { ImageConfig, imageConfigDefault } from './image-config' import { ImageConfig, imageConfigDefault } from './image-config'
import { processBuffer, Operation } from './lib/squoosh/main' import { processBuffer, Operation } from './lib/squoosh/main'
...@@ -30,9 +31,10 @@ export async function imageOptimizer( ...@@ -30,9 +31,10 @@ export async function imageOptimizer(
server: Server, server: Server,
req: IncomingMessage, req: IncomingMessage,
res: ServerResponse, res: ServerResponse,
parsedUrl: UrlWithParsedQuery parsedUrl: UrlWithParsedQuery,
nextConfig: NextConfig,
distDir: string
) { ) {
const { nextConfig, distDir } = server
const imageData: ImageConfig = nextConfig.images || imageConfigDefault const imageData: ImageConfig = nextConfig.images || imageConfigDefault
const { deviceSizes = [], imageSizes = [], domains = [], loader } = imageData const { deviceSizes = [], imageSizes = [], domains = [], loader } = imageData
......
...@@ -124,18 +124,18 @@ export type ServerConstructor = { ...@@ -124,18 +124,18 @@ export type ServerConstructor = {
} }
export default class Server { export default class Server {
dir: string protected dir: string
quiet: boolean protected quiet: boolean
nextConfig: NextConfig protected nextConfig: NextConfig
distDir: string protected distDir: string
pagesDir?: string protected pagesDir?: string
publicDir: string protected publicDir: string
hasStaticDir: boolean protected hasStaticDir: boolean
serverBuildDir: string protected serverBuildDir: string
pagesManifest?: PagesManifest protected pagesManifest?: PagesManifest
buildId: string protected buildId: string
minimalMode: boolean protected minimalMode: boolean
renderOpts: { protected renderOpts: {
poweredByHeader: boolean poweredByHeader: boolean
buildId: string buildId: string
generateEtags: boolean generateEtags: boolean
...@@ -161,7 +161,7 @@ export default class Server { ...@@ -161,7 +161,7 @@ export default class Server {
private compression?: Middleware private compression?: Middleware
private onErrorMiddleware?: ({ err }: { err: Error }) => Promise<void> private onErrorMiddleware?: ({ err }: { err: Error }) => Promise<void>
private incrementalCache: IncrementalCache private incrementalCache: IncrementalCache
router: Router protected router: Router
protected dynamicRoutes?: DynamicRoutes protected dynamicRoutes?: DynamicRoutes
protected customRoutes: CustomRoutes protected customRoutes: CustomRoutes
...@@ -784,7 +784,14 @@ export default class Server { ...@@ -784,7 +784,14 @@ export default class Server {
type: 'route', type: 'route',
name: '_next/image catchall', name: '_next/image catchall',
fn: (req, res, _params, parsedUrl) => fn: (req, res, _params, parsedUrl) =>
imageOptimizer(server, req, res, parsedUrl), imageOptimizer(
server,
req,
res,
parsedUrl,
server.nextConfig,
server.distDir
),
}, },
{ {
match: route('/_next/:path*'), match: route('/_next/:path*'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment