Commit 5d5af484 authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Don't treat static as an internal route when the folder is not provided (#9394)

* Render 404 for isInternalUrl in render

* Fix internal handling for static dir
parent 8dd8fb8f
...@@ -38,7 +38,7 @@ import Router, { Params, route, Route, RouteMatch } from './router' ...@@ -38,7 +38,7 @@ import Router, { Params, route, Route, RouteMatch } from './router'
import { sendHTML } from './send-html' import { sendHTML } from './send-html'
import { serveStatic } from './serve-static' import { serveStatic } from './serve-static'
import { getSprCache, initializeSprCache, setSprCache } from './spr-cache' import { getSprCache, initializeSprCache, setSprCache } from './spr-cache'
import { isBlockedPage, isInternalUrl } from './utils' import { isBlockedPage } from './utils'
const getCustomRouteMatcher = pathMatch(true) const getCustomRouteMatcher = pathMatch(true)
...@@ -83,6 +83,7 @@ export default class Server { ...@@ -83,6 +83,7 @@ export default class Server {
distDir: string distDir: string
pagesDir?: string pagesDir?: string
publicDir: string publicDir: string
hasStaticDir: boolean
pagesManifest: string pagesManifest: string
buildId: string buildId: string
renderOpts: { renderOpts: {
...@@ -120,6 +121,7 @@ export default class Server { ...@@ -120,6 +121,7 @@ export default class Server {
this.nextConfig = loadConfig(phase, this.dir, conf) this.nextConfig = loadConfig(phase, this.dir, conf)
this.distDir = join(this.dir, this.nextConfig.distDir) this.distDir = join(this.dir, this.nextConfig.distDir)
this.publicDir = join(this.dir, CLIENT_PUBLIC_FILES_PATH) this.publicDir = join(this.dir, CLIENT_PUBLIC_FILES_PATH)
this.hasStaticDir = fs.existsSync(join(this.dir, 'static'))
this.pagesManifest = join( this.pagesManifest = join(
this.distDir, this.distDir,
this.nextConfig.target === 'server' this.nextConfig.target === 'server'
...@@ -268,7 +270,7 @@ export default class Server { ...@@ -268,7 +270,7 @@ export default class Server {
? this.generatePublicRoutes() ? this.generatePublicRoutes()
: [] : []
const staticFilesRoute = fs.existsSync(join(this.dir, 'static')) const staticFilesRoute = this.hasStaticDir
? [ ? [
{ {
// It's very important to keep this route's param optional. // It's very important to keep this route's param optional.
...@@ -595,7 +597,11 @@ export default class Server { ...@@ -595,7 +597,11 @@ export default class Server {
parsedUrl?: UrlWithParsedQuery parsedUrl?: UrlWithParsedQuery
): Promise<void> { ): Promise<void> {
const url: any = req.url const url: any = req.url
if (isInternalUrl(url)) {
if (
url.match(/^\/_next\//) ||
(this.hasStaticDir && url.match(/^\/static\//))
) {
return this.handleRequest(req, res, parsedUrl) return this.handleRequest(req, res, parsedUrl)
} }
......
import { BLOCKED_PAGES } from '../lib/constants' import { BLOCKED_PAGES } from '../lib/constants'
const internalPrefixes = [/^\/_next\//, /^\/static\//]
export function isInternalUrl(url: string): boolean {
for (const prefix of internalPrefixes) {
if (prefix.test(url)) {
return true
}
}
return false
}
export function isBlockedPage(pathname: string): boolean { export function isBlockedPage(pathname: string): boolean {
return BLOCKED_PAGES.indexOf(pathname) !== -1 return BLOCKED_PAGES.indexOf(pathname) !== -1
} }
......
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