Merge branch 'main' into rm-env-id

This commit is contained in:
Max Peintner
2025-02-24 16:57:25 +01:00
committed by GitHub
7 changed files with 28 additions and 43 deletions

View File

@@ -14,14 +14,6 @@ declare namespace NodeJS {
*/
ZITADEL_API_URL: string;
/**
* Takes effect only if ZITADEL_API_URL is not empty.
* This is only relevant if Zitadels runtime has the ZITADEL_INSTANCEHOSTHEADERS config changed.
* The default is x-zitadel-instance-host.
* Most users don't need to set this variable.
*/
ZITADEL_INSTANCE_HOST_HEADER: string;
/**
* Self hosting: The service user token
*/
@@ -31,5 +23,11 @@ declare namespace NodeJS {
* Optional: wheter a user must have verified email
*/
EMAIL_VERIFICATION: string;
/**
* Optional: custom request headers to be added to every request
* Split by comma, key value pairs separated by colon
*/
CUSTOM_REQUEST_HEADERS: string;
}
}

View File

@@ -42,26 +42,23 @@ export async function createServiceForHost<T extends ServiceClass>(
throw new Error("No token found");
}
const instanceHost = new URL(serviceUrl).host;
const transport = createServerTransport(token, {
baseUrl: process.env.ZITADEL_API_URL ?? serviceUrl,
interceptors:
(process.env.ZITADEL_API_URL &&
process.env.ZITADEL_API_URL != serviceUrl) ||
process.env.ZITADEL_INSTANCE_HOST_HEADER
? [
(next) => {
return (req) => {
req.header.set(
process.env.ZITADEL_INSTANCE_HOST_HEADER ??
"x-zitadel-instance-host",
instanceHost,
);
return next(req);
};
},
]
: undefined,
baseUrl: serviceUrl,
interceptors: !process.env.CUSTOM_REQUEST_HEADERS
? undefined
: [
(next) => {
return (req) => {
process.env.CUSTOM_REQUEST_HEADERS.split(",").forEach(
(header) => {
const kv = header.split(":");
req.header.set(kv[0], kv[1]);
},
);
return next(req);
};
},
],
});
return createClientFor<T>(service)(transport);