forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add /route subpath to metadata static routes (vercel#47030)
Set the output bundle file path to `/<metadata route>/route.js` to align with other custom app routes, in order to make it easier being handled by app routes in both nextjs and vercel
- Loading branch information
Showing
6 changed files
with
38 additions
and
21 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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import path from '../shared/lib/isomorphic/path' | ||
|
||
export function isAppRouteRoute(route: string): boolean { | ||
return route.endsWith('/route') | ||
} | ||
|
||
// Match routes that are metadata routes, e.g. /sitemap.xml, /favicon.<ext>, /<icon>.<ext>, etc. | ||
// TODO-METADATA: support more metadata routes with more extensions | ||
const staticMetadataRoutes = ['robots.txt', 'sitemap.xml', 'favicon.ico'] | ||
const staticMetadataRoutes = [/robots\.txt/, /sitemap\.xml/, /favicon\.ico/] | ||
export function isMetadataRoute(route: string): boolean { | ||
// Remove the 'app/' or '/' prefix, only check the route name since they're only allowed in root app directory | ||
const filename = route.replace(/^app\//, '').replace(/^\//, '') | ||
return staticMetadataRoutes.includes(filename) | ||
const filename = route | ||
.replace(/^app\//, '') | ||
.replace(/^\//, '') | ||
.replace(/\/route$/, '') | ||
return staticMetadataRoutes.some((r) => r.test(filename)) | ||
} | ||
|
||
// Only match the static metadata files | ||
// TODO-METADATA: support static metadata files under nested routes folders | ||
export function isStaticMetadataRoute(resourcePath: string) { | ||
const filename = path.basename(resourcePath) | ||
return staticMetadataRoutes.includes(filename) | ||
return staticMetadataRoutes.some((r) => r.test(resourcePath)) | ||
} |
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,5 @@ | ||
import { NextResponse } from 'next/server' | ||
|
||
export function GET() { | ||
return new NextResponse('hello api route') | ||
} |
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