0

Update redirect/rewrite rule priority

by
Published Oct 17, 2025

Update the priority for a particular redirect/rewrite rule. To apply redirect/rewrite rules to an incoming request, Render starts from the rule with priority `0` and applies the first encountered rule that matches the request's path (if any). Render increments the priority of other rules by `1` as necessary to make space for the updated rule.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * Update redirect/rewrite rule priority
7
 * Update the priority for a particular redirect/rewrite rule.
8

9
To apply redirect/rewrite rules to an incoming request, Render starts from the rule with priority `0` and applies the first encountered rule that matches the request's path (if any).
10

11
Render increments the priority of other rules by `1` as necessary to make space for the updated rule.
12

13
 */
14
export async function main(auth: Render, serviceId: string, body: { priority: number }) {
15
	const url = new URL(`https://api.render.com/v1/services/${serviceId}/routes`)
16

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