mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-03 09:16:40 +00:00
Chungus
This commit is contained in:
@@ -4,6 +4,9 @@ import HttpCode from "@server/types/HttpCode";
|
||||
import createHttpError from "http-errors";
|
||||
import logger from "@server/logger";
|
||||
import { fromError } from "zod-validation-error";
|
||||
import { resolveExitNodes } from "@server/lib/exitNodes";
|
||||
import config from "@server/lib/config";
|
||||
import { build } from "@server/build";
|
||||
|
||||
// Define Zod schema for request validation
|
||||
const getResolvedHostnameSchema = z.object({
|
||||
@@ -17,22 +20,42 @@ export async function getResolvedHostname(
|
||||
next: NextFunction
|
||||
): Promise<any> {
|
||||
try {
|
||||
// Validate request parameters
|
||||
const parsedParams = getResolvedHostnameSchema.safeParse(
|
||||
req.body
|
||||
);
|
||||
if (!parsedParams.success) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
fromError(parsedParams.error).toString()
|
||||
)
|
||||
let endpoints: string[] = []; // always route locally
|
||||
|
||||
if (build != "oss") {
|
||||
// Validate request parameters
|
||||
const parsedParams = getResolvedHostnameSchema.safeParse(req.body);
|
||||
if (!parsedParams.success) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
fromError(parsedParams.error).toString()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const { hostname, publicKey } = parsedParams.data;
|
||||
|
||||
const baseDomain = config.getRawPrivateConfig().app.base_domain;
|
||||
|
||||
// if the hostname ends with the base domain then send back a empty array
|
||||
if (baseDomain && hostname.endsWith(baseDomain)) {
|
||||
return res.status(HttpCode.OK).send({
|
||||
endpoints: [] // this should force to route locally
|
||||
});
|
||||
}
|
||||
|
||||
const resourceExitNodes = await resolveExitNodes(
|
||||
hostname,
|
||||
publicKey
|
||||
);
|
||||
|
||||
endpoints = resourceExitNodes.map((node) => node.endpoint);
|
||||
}
|
||||
|
||||
// return the endpoints
|
||||
return res.status(HttpCode.OK).send({
|
||||
endpoints: [] // ALWAYS ROUTE LOCALLY
|
||||
endpoints
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
|
||||
Reference in New Issue
Block a user