//native
type Vercel = {
token: string;
};
/**
* Add a domain to a project
* Add a domain to the project by passing its domain name and by specifying the project by either passing the project `id` or `name` in the URL. If the domain is not yet verified to be used on this project, the request will return `verified = false`, and the domain will need to be verified according to the `verification` challenge via `POST /projects/:idOrName/domains/:domain/verify`. If the domain already exists on the project, the request will fail with a `400` status code.
*/
export async function main(
auth: Vercel,
idOrName: string,
teamId: string | undefined,
slug: string | undefined,
body: {
name: string;
gitBranch?: string;
customEnvironmentId?: string;
redirect?: string;
redirectStatusCode?: 301 | 302 | 307 | 308;
},
) {
const url = new URL(
`https://api.vercel.com/v10/projects/${idOrName}/domains`,
);
for (const [k, v] of [
["teamId", teamId],
["slug", slug],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago