//native
type Render = {
apiKey: string
}
/**
* Update redirect/rewrite rules
* Replace all redirect/rewrite rules for a particular service with the provided list.
**This deletes all existing redirect/rewrite rules for the service that aren't included in the request.**
Rule priority is assigned according to list order (the first rule in the list has the highest priority).
*/
export async function main(
auth: Render,
serviceId: string,
body: { type: 'redirect' | 'rewrite'; source: string; destination: string }[]
) {
const url = new URL(`https://api.render.com/v1/services/${serviceId}/routes`)
const response = await fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.apiKey
},
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 235 days ago