rsnext/packages/next/next-server/lib/router/rewrite-url-for-export.ts
Tim Neutkens 2ba352da39 Move next-server back into next package (#8613)
* Initial move

* Make emitting work

* Update paths

* Remove leftover files

* Add correct externals configuration

* Import correct path

* Update path to work with ts-server test

* Update lib directory

* Compile next-server/lib
2019-09-04 10:00:54 -04:00

11 lines
395 B
TypeScript

export function rewriteUrlForNextExport(url: string): string {
const [pathname, hash] = url.split('#')
// tslint:disable-next-line
let [path, qs] = pathname.split('?')
path = path.replace(/\/$/, '')
// Append a trailing slash if this path does not have an extension
if (!/\.[^/]+\/?$/.test(path)) path += `/`
if (qs) path += '?' + qs
if (hash) path += '#' + hash
return path
}