Skip to content

Commit 58624b1

Browse files
committed
(Fixes #5) Update endpoints full_url when service base_url changes.
1 parent 292c2ff commit 58624b1

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
create or replace function update_full_url(p_service_id integer)
2+
returns void
3+
security definer
4+
language plpgsql
5+
as
6+
$$
7+
begin
8+
update public.endpoints e
9+
set full_url = concat(s.base_url, e.name)
10+
from public.services s
11+
where s.id = p_service_id and e.service_id = s.id;
12+
end;
13+
$$;

packages/dashboard/src/app/api/service/route.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NextResponse } from 'next/server';
22
import { randomBytes, createCipheriv } from "crypto";
3-
import {dropServiceEndpointsCaches} from "@/app/api/utils";
3+
import { dropServiceEndpointsCaches } from "@/app/api/utils";
44
import { createClient } from '@/utils/supabase/server';
55
import { env } from 'next-runtime-env';
66

@@ -49,10 +49,16 @@ export async function POST(req: Request) {
4949
.eq("id", body.id)
5050
.select()
5151
.single();
52+
53+
if (result.error) throw result.error;
54+
55+
result = await supabase.rpc("update_full_url", { p_service_id: body.id })
5256
}
5357

5458
if (result.error) throw result.error;
59+
5560
await dropServiceEndpointsCaches(userId!, body.serviceName);
61+
5662
return NextResponse.json(result.data);
5763
} catch (error: any) {
5864
return NextResponse.json(

0 commit comments

Comments
 (0)