This commit is contained in:
2025-05-29 01:07:39 +00:00
parent d8d1bdcd41
commit 200a735876
5 changed files with 213 additions and 155 deletions

View File

@ -143,30 +143,12 @@ export function validateRouteAction(action: IRouteAction): { valid: boolean; err
}
}
// Validate redirect for 'redirect' action
if (action.type === 'redirect') {
if (!action.redirect) {
errors.push('Redirect configuration is required for redirect action');
} else {
if (!action.redirect.to) {
errors.push('Redirect target (to) is required');
}
if (action.redirect.status &&
![301, 302, 303, 307, 308].includes(action.redirect.status)) {
errors.push('Invalid redirect status code');
}
}
}
// Validate static file config for 'static' action
if (action.type === 'static') {
if (!action.static) {
errors.push('Static file configuration is required for static action');
} else {
if (!action.static.root) {
errors.push('Static file root directory is required');
}
// Validate socket handler for 'socket-handler' action
if (action.type === 'socket-handler') {
if (!action.socketHandler) {
errors.push('Socket handler function is required for socket-handler action');
} else if (typeof action.socketHandler !== 'function') {
errors.push('Socket handler must be a function');
}
}
@ -261,12 +243,8 @@ export function hasRequiredPropertiesForAction(route: IRouteConfig, actionType:
switch (actionType) {
case 'forward':
return !!route.action.target && !!route.action.target.host && !!route.action.target.port;
case 'redirect':
return !!route.action.redirect && !!route.action.redirect.to;
case 'static':
return !!route.action.static && !!route.action.static.root;
case 'block':
return true; // Block action doesn't require additional properties
case 'socket-handler':
return !!route.action.socketHandler && typeof route.action.socketHandler === 'function';
default:
return false;
}