move changes to other pr

This commit is contained in:
Elio Bischof
2025-02-21 11:16:53 +01:00
parent 31d15abe29
commit c613f18741
2 changed files with 27 additions and 1 deletions

View File

@@ -14,6 +14,14 @@ 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 id
*/

View File

@@ -42,8 +42,26 @@ export async function createServiceForHost<T extends ServiceClass>(
throw new Error("No token found");
}
const instanceHost = new URL(serviceUrl).host;
const transport = createServerTransport(token, {
baseUrl: serviceUrl,
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,
});
return createClientFor<T>(service)(transport);