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'
import { join } from 'path'
import Stream from 'stream'
import nodeUrl, { UrlWithParsedQuery } from 'url'
import { NextConfig } from '../../next-server/server/config-shared'
import { fileExists } from '../../lib/file-exists'
import { ImageConfig, imageConfigDefault } from './image-config'
import { processBuffer, Operation } from './lib/squoosh/main'
......@@ -30,9 +31,10 @@ export async function imageOptimizer(
server: Server,
req: IncomingMessage,
res: ServerResponse,
parsedUrl: UrlWithParsedQuery
parsedUrl: UrlWithParsedQuery,
nextConfig: NextConfig,
distDir: string
) {
const { nextConfig, distDir } = server
const imageData: ImageConfig = nextConfig.images || imageConfigDefault
const { deviceSizes = [], imageSizes = [], domains = [], loader } = imageData
......
......@@ -124,18 +124,18 @@ export type ServerConstructor = {
}
export default class Server {
dir: string
quiet: boolean
nextConfig: NextConfig
distDir: string
pagesDir?: string
publicDir: string
hasStaticDir: boolean
serverBuildDir: string
pagesManifest?: PagesManifest
buildId: string
minimalMode: boolean
renderOpts: {
protected dir: string
protected quiet: boolean
protected nextConfig: NextConfig
protected distDir: string
protected pagesDir?: string
protected publicDir: string
protected hasStaticDir: boolean
protected serverBuildDir: string
protected pagesManifest?: PagesManifest
protected buildId: string
protected minimalMode: boolean
protected renderOpts: {
poweredByHeader: boolean
buildId: string
generateEtags: boolean
......@@ -161,7 +161,7 @@ export default class Server {
private compression?: Middleware
private onErrorMiddleware?: ({ err }: { err: Error }) => Promise<void>
private incrementalCache: IncrementalCache
router: Router
protected router: Router
protected dynamicRoutes?: DynamicRoutes
protected customRoutes: CustomRoutes
......@@ -784,7 +784,14 @@ export default class Server {
type: 'route',
name: '_next/image catchall',
fn: (req, res, _params, parsedUrl) =>
imageOptimizer(server, req, res, parsedUrl),
imageOptimizer(
server,
req,
res,
parsedUrl,
server.nextConfig,
server.distDir
),
},
{
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