fix(coolify): upsertServiceEnv falls back to PATCH on already-exists
Coolify auto-creates env entries (with empty values) for every ${VAR}
reference it finds in the compose YAML at service-creation time. So
POST /services/{uuid}/envs returns 'already exists' for any env we
try to set after creation. The fix is to fall back to PATCH on that
specific error, making the helper a true upsert.
Made-with: Cursor
This commit is contained in:
@@ -576,10 +576,26 @@ export async function upsertServiceEnv(
|
|||||||
uuid: string,
|
uuid: string,
|
||||||
env: ServiceEnvVar,
|
env: ServiceEnvVar,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
// Coolify auto-creates env entries (with empty values) for every
|
||||||
|
// ${VAR} reference in the compose file at service-creation time.
|
||||||
|
// POST to /envs returns "already exists" for those — we must use
|
||||||
|
// PATCH to update them. Try POST first, fall back to PATCH.
|
||||||
|
try {
|
||||||
await coolifyFetch(`/services/${uuid}/envs`, {
|
await coolifyFetch(`/services/${uuid}/envs`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(env),
|
body: JSON.stringify(env),
|
||||||
});
|
});
|
||||||
|
} catch (err: unknown) {
|
||||||
|
const msg = err instanceof Error ? err.message : String(err);
|
||||||
|
if (msg.includes('already exists')) {
|
||||||
|
await coolifyFetch(`/services/${uuid}/envs`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
body: JSON.stringify(env),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listAllServices(): Promise<Array<Record<string, unknown>>> {
|
export async function listAllServices(): Promise<Array<Record<string, unknown>>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user