0

Add a domain

by
Published Apr 8, 2025

Add a new domain for your instance. Useful in the case of multi-domain instances, allows adding satellite domains to an instance. The new domain must have a `name`. The domain name can contain the port for development instances, like `localhost:3000`. At the moment, instances can have only one primary domain, so the `is_satellite` parameter must be set to `true`. If you're planning to configure the new satellite domain to run behind a proxy, pass the `proxy_url` parameter accordingly.

Script clerk Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Clerk = {
3
  apiKey: string;
4
};
5
/**
6
 * Add a domain
7
 * Add a new domain for your instance.
8
Useful in the case of multi-domain instances, allows adding satellite domains to an instance.
9
The new domain must have a `name`. The domain name can contain the port for development instances, like `localhost:3000`.
10
At the moment, instances can have only one primary domain, so the `is_satellite` parameter must be set to `true`.
11
If you're planning to configure the new satellite domain to run behind a proxy, pass the `proxy_url` parameter accordingly.
12
 */
13
export async function main(
14
  auth: Clerk,
15
  body: { name: string; is_satellite: true; proxy_url?: string },
16
) {
17
  const url = new URL(`https://api.clerk.com/v1/domains`);
18

19
  const response = await fetch(url, {
20
    method: "POST",
21
    headers: {
22
      "Content-Type": "application/json",
23
      Authorization: "Bearer " + auth.apiKey,
24
    },
25
    body: JSON.stringify(body),
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33