mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-11 13:16:38 +00:00
add missing path / validation
This commit is contained in:
@@ -108,12 +108,12 @@ function validatePathRewriteConfig(
|
|||||||
return { isValid: true };
|
return { isValid: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rewritePathType !== "stripPrefix") {
|
||||||
if ((rewritePath && !rewritePathType) || (!rewritePath && rewritePathType)) {
|
if ((rewritePath && !rewritePathType) || (!rewritePath && rewritePathType)) {
|
||||||
return {
|
return { isValid: false, error: "Both rewritePath and rewritePathType must be specified together" };
|
||||||
isValid: false,
|
|
||||||
error: "Both rewritePath and rewritePathType must be specified together"
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!rewritePath || !rewritePathType) {
|
if (!rewritePath || !rewritePathType) {
|
||||||
return { isValid: true };
|
return { isValid: true };
|
||||||
@@ -146,26 +146,12 @@ function validatePathRewriteConfig(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate path formats for non-regex types
|
|
||||||
if (pathMatchType !== "regex" && !path.startsWith("/")) {
|
|
||||||
return {
|
|
||||||
isValid: false,
|
|
||||||
error: "Path must start with '/' for exact and prefix matching"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Additional validation for stripPrefix
|
// Additional validation for stripPrefix
|
||||||
if (rewritePathType === "stripPrefix") {
|
if (rewritePathType === "stripPrefix") {
|
||||||
if (pathMatchType !== "prefix") {
|
if (pathMatchType !== "prefix") {
|
||||||
logger.warn(`stripPrefix rewrite type is most effective with prefix path matching. Current match type: ${pathMatchType}`);
|
logger.warn(`stripPrefix rewrite type is most effective with prefix path matching. Current match type: ${pathMatchType}`);
|
||||||
}
|
}
|
||||||
// For stripPrefix, rewritePath is optional (can be empty to just strip)
|
|
||||||
if (rewritePath && !rewritePath.startsWith("/") && rewritePath !== "") {
|
|
||||||
return {
|
|
||||||
isValid: false,
|
|
||||||
error: "stripPrefix rewritePath must start with '/' or be empty"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { isValid: true };
|
return { isValid: true };
|
||||||
@@ -181,6 +167,14 @@ function createPathRewriteMiddleware(
|
|||||||
): { middlewares: { [key: string]: any }; chain?: string[] } {
|
): { middlewares: { [key: string]: any }; chain?: string[] } {
|
||||||
const middlewares: { [key: string]: any } = {};
|
const middlewares: { [key: string]: any } = {};
|
||||||
|
|
||||||
|
if (pathMatchType !== "regex" && !path.startsWith("/")) {
|
||||||
|
path = `/${path}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rewritePathType !== "regex" && rewritePath !== "" && !rewritePath.startsWith("/")) {
|
||||||
|
rewritePath = `/${rewritePath}`;
|
||||||
|
}
|
||||||
|
|
||||||
switch (rewritePathType) {
|
switch (rewritePathType) {
|
||||||
case "exact":
|
case "exact":
|
||||||
// Replace the path with the exact rewrite path
|
// Replace the path with the exact rewrite path
|
||||||
|
|||||||
Reference in New Issue
Block a user