mirror of
https://github.com/fosrl/pangolin.git
synced 2026-10-20 19:49:05 +02:00
add hybrid route for remote nodes
This commit is contained in:
@@ -96,12 +96,20 @@ import semver from "semver";
|
||||
import { maxmindAsnLookup } from "@server/db/maxmindAsn";
|
||||
import { checkOrgAccessPolicy } from "@server/lib/checkOrgAccessPolicy";
|
||||
import { sanitizeString } from "@server/lib/sanitize";
|
||||
import {
|
||||
getRedirectsByHost,
|
||||
type RedirectByHost
|
||||
} from "@server/db/queries/verifySessionQueries";
|
||||
|
||||
// Zod schemas for request validation
|
||||
const getResourceByDomainParamsSchema = z.strictObject({
|
||||
domain: z.string().min(1, "Domain is required")
|
||||
});
|
||||
|
||||
const getRedirectsByHostParamsSchema = z.strictObject({
|
||||
host: z.string().min(1, "Host is required")
|
||||
});
|
||||
|
||||
const getUserSessionParamsSchema = z.strictObject({
|
||||
userSessionId: z.string().min(1, "User session ID is required")
|
||||
});
|
||||
@@ -818,6 +826,44 @@ hybridRouter.get(
|
||||
}
|
||||
);
|
||||
|
||||
hybridRouter.get(
|
||||
"/redirects/host/:host",
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const parsedParams = getRedirectsByHostParamsSchema.safeParse(
|
||||
req.params
|
||||
);
|
||||
if (!parsedParams.success) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
fromError(parsedParams.error).toString()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const { host } = parsedParams.data;
|
||||
const redirects = await getRedirectsByHost(host);
|
||||
|
||||
return response<RedirectByHost[]>(res, {
|
||||
data: redirects,
|
||||
success: true,
|
||||
error: false,
|
||||
message: "Redirects retrieved successfully",
|
||||
status: HttpCode.OK
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.INTERNAL_SERVER_ERROR,
|
||||
"Failed to get redirects by host"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const getOrgLoginPageParamsSchema = z.strictObject({
|
||||
orgId: z.string().min(1)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user