forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce hello-world middleware bundle size from 128k to 88k (vercel#35512
) Moves two utility functions from `server/router.ts` into their own file. This avoids the middleware pulling in the full Next.js router into its bundle. There are probably more opportunities like this, but this is a good start. Middleware should likely be bundled by a non-chunking optimizing compiler.
- Loading branch information
Showing
5 changed files
with
23 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export function replaceBasePath(pathname: string, basePath: string): string { | ||
// ensure basePath is only stripped if it matches exactly | ||
// and doesn't contain extra chars e.g. basePath /docs | ||
// should replace for /docs, /docs/, /docs/a but not /docsss | ||
if (hasBasePath(pathname, basePath)) { | ||
pathname = pathname.substr(basePath.length) | ||
if (!pathname.startsWith('/')) pathname = `/${pathname}` | ||
} | ||
return pathname | ||
} | ||
|
||
export function hasBasePath(pathname: string, basePath: string): boolean { | ||
return ( | ||
typeof pathname === 'string' && | ||
(pathname === basePath || pathname.startsWith(basePath + '/')) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters