rsnext/packages/next/next-server/server/normalize-page-path.ts
JJ Kasper a4c507d5b4
Update to use existing util to de-dupe path check (#10431)
* Update to use existing util to de-dupe path check

* Update error message for requested/resolved mismatch

* Use correct dataRoute value for prerender manifest

* Fix pageUrl having double slash on Windows
2020-02-05 22:10:39 +01:00

19 lines
599 B
TypeScript

import { posix } from 'path'
export function normalizePagePath(page: string): string {
// If the page is `/` we need to append `/index`, otherwise the returned directory root will be bundles instead of pages
if (page === '/') {
page = '/index'
}
// Resolve on anything that doesn't start with `/`
if (page[0] !== '/') {
page = `/${page}`
}
// Throw when using ../ etc in the pathname
const resolvedPage = posix.normalize(page)
if (page !== resolvedPage) {
throw new Error(
`Requested and resolved page mismatch: ${page} ${resolvedPage}`
)
}
return page
}