1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Refactor rendor verification to validate if it's a blocked page. (#5686)

Extracting the logic that defines if a page is blocked to utils.

If that refactor make sense, I will create a next PR to cover both of the functions inside utils with tests.
This commit is contained in:
Anderson Leite 2018-11-18 11:44:50 -08:00 committed by Tim Neutkens
parent 233a6042d9
commit 79095bc500
2 changed files with 9 additions and 3 deletions

View file

@ -10,9 +10,9 @@ import {
serveStatic
} from './render'
import Router, {route} from './router'
import { isInternalUrl } from './utils'
import { isInternalUrl, isBlockedPage } from './utils'
import loadConfig from 'next-server/next-config'
import {PHASE_PRODUCTION_SERVER, BLOCKED_PAGES, BUILD_ID_FILE, CLIENT_STATIC_FILES_PATH, CLIENT_STATIC_FILES_RUNTIME} from 'next-server/constants'
import {PHASE_PRODUCTION_SERVER, BUILD_ID_FILE, CLIENT_STATIC_FILES_PATH, CLIENT_STATIC_FILES_RUNTIME} from 'next-server/constants'
import * as asset from '../lib/asset'
import * as envConfig from '../lib/runtime-config'
import { isResSent } from '../lib/utils'
@ -177,7 +177,7 @@ export default class Server {
return this.handleRequest(req, res, parsedUrl)
}
if (BLOCKED_PAGES.indexOf(pathname) !== -1) {
if (isBlockedPage(pathname)) {
return await this.render404(req, res, parsedUrl)
}

View file

@ -1,3 +1,5 @@
import { BLOCKED_PAGES } from 'next-server/constants'
const internalPrefixes = [
/^\/_next\//,
/^\/static\//
@ -12,3 +14,7 @@ export function isInternalUrl (url) {
return false
}
export function isBlockedPage (pathname) {
return (BLOCKED_PAGES.indexOf(pathname) !== -1)
}