-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add additional metadata to RoutingResult #673
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c008911
add additional metadata to RoutingResult
conico974 ea9d397
review fix
conico974 0a6ee8d
handle multiple route
conico974 189a87e
add unit test
conico974 c737e11
review fix
conico974 4f46657
changeset
conico974 1b01210
fix lint
conico974 0be8461
review fix
conico974 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@opennextjs/aws": patch | ||
--- | ||
|
||
Add additional metadata to RoutingResult | ||
conico974 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
For some future features [#658](https://github.com/opennextjs/opennextjs-aws/issues/658) (and bug fix [#677](https://github.com/opennextjs/opennextjs-aws/issues/677)) we need to add some additional metadata to the RoutingResult. | ||
This PR adds 2 new fields to the RoutingResult: `initialPath` and `resolvedRoutes` |
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
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,57 @@ | ||
import { AppPathRoutesManifest, RoutesManifest } from "config/index"; | ||
import type { RouteDefinition } from "types/next-types"; | ||
import type { RouteType } from "types/open-next"; | ||
|
||
// Add the locale prefix to the regex so we correctly match the rawPath | ||
const optionalLocalePrefixRegex = `^/(?:${RoutesManifest.locales.map((locale) => `${locale}/?`).join("|")})?`; | ||
|
||
// Add the basepath prefix to the regex so we correctly match the rawPath | ||
const optionalBasepathPrefixRegex = RoutesManifest.basePath | ||
? `^${RoutesManifest.basePath}/?` | ||
: "^/"; | ||
|
||
// Add the basePath prefix to the api routes | ||
export const apiPrefix = `${RoutesManifest.basePath ?? ""}/api`; | ||
|
||
const optionalPrefix = optionalLocalePrefixRegex.replace( | ||
"^/", | ||
optionalBasepathPrefixRegex, | ||
); | ||
|
||
function routeMatcher(routeDefinitions: RouteDefinition[]) { | ||
const regexp = routeDefinitions.map((route) => ({ | ||
page: route.page, | ||
regexp: new RegExp(route.regex.replace("^/", optionalPrefix)), | ||
})); | ||
|
||
const appPathsSet = new Set(); | ||
const routePathsSet = new Set(); | ||
// We need to use AppPathRoutesManifest here | ||
for (const [k, v] of Object.entries(AppPathRoutesManifest)) { | ||
if (k.endsWith("page")) { | ||
appPathsSet.add(v); | ||
} else if (k.endsWith("route")) { | ||
routePathsSet.add(v); | ||
} | ||
} | ||
|
||
return function matchRoute(path: string) { | ||
const foundRoutes = regexp.filter((route) => route.regexp.test(path)); | ||
|
||
return foundRoutes.map((foundRoute) => { | ||
let routeType: RouteType = "page"; | ||
if (appPathsSet.has(foundRoute.page)) { | ||
routeType = "app"; | ||
} else if (routePathsSet.has(foundRoute.page)) { | ||
routeType = "route"; | ||
} | ||
return { | ||
route: foundRoute.page, | ||
type: routeType, | ||
}; | ||
}); | ||
}; | ||
} | ||
|
||
export const staticRouteMatcher = routeMatcher(RoutesManifest.routes.static); | ||
export const dynamicRouteMatcher = routeMatcher(RoutesManifest.routes.dynamic); |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be minor (new feature) instead of patch (bug fix) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok this way, technically there is no new feature here, and it should have no impact at all for end user (even people with custom overrides)
Other PR that will depend on this one will be minor like #665