Skip to content

Commit df56c77

Browse files
fix get resources
1 parent 3969ef9 commit df56c77

File tree

2 files changed

+16
-37
lines changed

2 files changed

+16
-37
lines changed

server/routers/resource/getResource.ts

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const getResourceHostnamesParamsSchema = z
2424
})
2525
.strict();
2626

27-
2827
async function query(resourceId?: number, niceId?: string, orgId?: string) {
2928
if (resourceId) {
3029
const [res] = await db
@@ -43,8 +42,7 @@ async function query(resourceId?: number, niceId?: string, orgId?: string) {
4342
}
4443
}
4544

46-
export type GetResourceResponseWithHostnames = {
47-
data: Resource;
45+
export type GetResourceResponse = Resource & {
4846
hostMode: string;
4947
hostnames: Array<{
5048
hostnameId: number;
@@ -53,12 +51,9 @@ export type GetResourceResponseWithHostnames = {
5351
fullDomain: string;
5452
baseDomain: string;
5553
primary: boolean;
56-
createdAt: string;
5754
}>;
5855
};
5956

60-
export type GetResourceResponse = Resource;
61-
6257

6358
registry.registerPath({
6459
method: "get",
@@ -87,6 +82,7 @@ registry.registerPath({
8782
},
8883
responses: {}
8984
});
85+
9086
export async function getResource(
9187
req: Request,
9288
res: Response,
@@ -105,7 +101,6 @@ export async function getResource(
105101

106102
const { resourceId, niceId, orgId } = parsedParams.data;
107103

108-
// Use new query helper
109104
const resource = await query(resourceId, niceId, orgId);
110105

111106
if (!resource) {
@@ -114,19 +109,6 @@ export async function getResource(
114109
);
115110
}
116111

117-
// Only HTTP resources have hostnames
118-
if (!resource.http) {
119-
return response<GetResourceResponse>(res, {
120-
data: resource,
121-
success: true,
122-
error: false,
123-
message: "Resource retrieved successfully",
124-
status: HttpCode.OK
125-
});
126-
}
127-
128-
129-
// Get hostnames for the resource
130112
const hostnames = await db
131113
.select({
132114
hostnameId: resourceHostnames.hostnameId,
@@ -141,9 +123,9 @@ export async function getResource(
141123
.where(eq(resourceHostnames.resourceId, resource.resourceId))
142124
.orderBy(resourceHostnames.primary, resourceHostnames.createdAt);
143125

144-
return response<GetResourceResponseWithHostnames>(res, {
126+
return response<GetResourceResponse>(res, {
145127
data: {
146-
data: resource,
128+
...resource,
147129
hostMode: resource.hostMode || "multi",
148130
hostnames: hostnames.map(h => ({
149131
hostnameId: h.hostnameId,
@@ -152,18 +134,17 @@ export async function getResource(
152134
fullDomain: h.fullDomain,
153135
baseDomain: h.baseDomain,
154136
primary: h.primary,
155-
createdAt: h.createdAt
156-
}))
137+
})),
157138
},
158139
success: true,
159140
error: false,
160-
message: "Resource hostnames retrieved successfully",
161-
status: HttpCode.OK
141+
message: "Resource retrieved successfully",
142+
status: HttpCode.OK,
162143
});
163144
} catch (error) {
164145
logger.error(error);
165146
return next(
166147
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
167148
);
168149
}
169-
}
150+
}

src/app/[orgId]/settings/resources/[niceId]/general/page.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,13 @@ export default function GeneralForm() {
371371
? `${sanitizedSubdomain}.${pendingDomain.baseDomain}`
372372
: pendingDomain.baseDomain;
373373

374+
setResourceFullDomain(`${resource.ssl ? "https" : "http"}://${sanitizedFullDomain}`);
375+
374376

375377
const updatedHostname: HostnameEntry = {
376378
...currentHostname,
377379
domainId: pendingDomain.domainId,
378-
subdomain: sanitizedSubdomain || undefined,
380+
subdomain: pendingDomain.subdomain,
379381
baseDomain: pendingDomain.baseDomain,
380382
fullDomain: sanitizedFullDomain
381383
};
@@ -644,7 +646,7 @@ export default function GeneralForm() {
644646
<div className="border p-2 rounded-md flex items-center justify-between">
645647
<span className="text-sm text-muted-foreground flex items-center gap-2">
646648
<Globe size="14" />
647-
{resourceFullDomain}
649+
{toUnicode(resourceFullDomain || "")}
648650
</span>
649651
</div>
650652
</div>
@@ -757,13 +759,7 @@ export default function GeneralForm() {
757759
>
758760
<div className="min-w-0">
759761
<div className="font-mono text-sm truncate">
760-
{h.fullDomain}
761-
</div>
762-
<div className="text-[11px] text-muted-foreground">
763-
{h.subdomain
764-
? `${h.subdomain}.`
765-
: ""}
766-
{h.baseDomain}
762+
{toUnicode(h.fullDomain || "")}
767763
</div>
768764
</div>
769765

@@ -902,10 +898,12 @@ export default function GeneralForm() {
902898
const sanitizedSubdomain = pendingDomain.subdomain
903899
? finalizeSubdomainSanitize(pendingDomain.subdomain)
904900
: "";
905-
901+
906902
const sanitizedFullDomain = sanitizedSubdomain
907903
? `${sanitizedSubdomain}.${pendingDomain.baseDomain}`
908904
: pendingDomain.baseDomain;
905+
906+
setResourceFullDomain(`${resource.ssl ? "https" : "http"}://${sanitizedFullDomain}`);
909907

910908
upsertHostname({
911909
domainId: pendingDomain.domainId,

0 commit comments

Comments
 (0)