Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark this.router protected #23573

Merged
merged 4 commits into from Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/next/next-server/server/image-optimizer.ts
Expand Up @@ -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'
Expand All @@ -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

Expand Down
35 changes: 21 additions & 14 deletions packages/next/next-server/server/next-server.ts
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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*'),
Expand Down