-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add redirect util function for project custom actions
- Loading branch information
Showing
3 changed files
with
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Extracts the redirect URL from request headers for AdminJS actions | ||
* @param request - The AdminJS action request object | ||
* @param resourceName - The name of the resource (e.g., 'Project', 'User') | ||
* @returns The URL to redirect to after action completion | ||
*/ | ||
export const getRedirectUrl = (request: any, resourceName: string): string => { | ||
const refererIndex = request.rawHeaders.findIndex(h => h.toLowerCase() === 'referer'); | ||
Check failure on line 8 in src/server/adminJs/adminJsUtils.ts GitHub Actions / test
|
||
const referrerUrl = refererIndex !== -1 ? request.rawHeaders[refererIndex + 1] : ''; | ||
|
||
// Default fallback URL if no referer is found | ||
const defaultUrl = `/admin/resources/${resourceName}`; | ||
|
||
try { | ||
if (referrerUrl) { | ||
const url = new URL(referrerUrl); | ||
return url.pathname + url.search; | ||
} | ||
} catch (error) { | ||
console.warn('Error parsing referrer URL:', error); | ||
} | ||
|
||
return defaultUrl; | ||
}; |
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