Skip to content

Commit 5fa18de

Browse files
james-crossJames-Cross
andauthored
updated both FindHelpPage and OrganisationPage to use relative paths for internal API fetches (#118)
Co-authored-by: James-Cross <james@streetsupport.net>
1 parent 19ae585 commit 5fa18de

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

src/app/find-help/organisation/[slug]/page.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ interface Props {
1313
export default async function OrganisationPage(props: Props) {
1414
const { slug } = await props.params;
1515

16-
const baseUrl = process.env.VERCEL_URL
17-
? `https://${process.env.VERCEL_URL}`
18-
: 'http://localhost:3000';
19-
20-
const res = await fetch(`${baseUrl}/api/service-providers/${slug}`, {
16+
// ✅ Use relative path for internal API call
17+
const res = await fetch(`/api/service-providers/${slug}`, {
2118
cache: 'no-store',
2219
});
2320

@@ -37,7 +34,6 @@ export default async function OrganisationPage(props: Props) {
3734
return notFound();
3835
}
3936

40-
// Cast services
4137
const rawServices = (data.services || []) as RawService[];
4238

4339
const services = rawServices.map((service, idx) => {
@@ -61,8 +57,8 @@ export default async function OrganisationPage(props: Props) {
6157
description: service.Info || '',
6258
address: service.Address || {},
6359
openTimes,
64-
organisation: data.organisation.name, // ✅ lowercase
65-
organisationSlug: data.organisation.key, // ✅ lowercase
60+
organisation: data.organisation.name,
61+
organisationSlug: data.organisation.key,
6662
latitude: coords[1],
6763
longitude: coords[0],
6864
clientGroups: service.ClientGroups || [],
@@ -86,7 +82,6 @@ export default async function OrganisationPage(props: Props) {
8682
groupedServices,
8783
};
8884

89-
9085
console.log('✅ DEBUG groupedServices:', JSON.stringify(groupedServices, null, 2));
9186

9287
return <OrganisationShell organisation={organisation} />;

src/app/find-help/page.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,8 @@ import { decodeHtmlEntities } from '@/utils/htmlDecode';
66
import { categoryKeyToName, subCategoryKeyToName } from '@/utils/categoryLookup';
77

88
export default async function FindHelpPage() {
9-
const isServer = typeof window === 'undefined';
10-
11-
const baseUrl = isServer
12-
? process.env.VERCEL_URL
13-
? `https://${process.env.VERCEL_URL}`
14-
: 'http://localhost:3000'
15-
: '';
16-
17-
const res = await fetch(`${baseUrl}/api/services?limit=1000`, { cache: 'no-store' });
9+
// ✅ Use relative URL for internal API call — safe for local and Vercel
10+
const res = await fetch('/api/services?limit=1000', { cache: 'no-store' });
1811

1912
if (!res.ok) {
2013
throw new Error(`Failed to fetch services: ${res.status}`);
@@ -66,4 +59,4 @@ export default async function FindHelpPage() {
6659
</div>
6760
</LocationProvider>
6861
);
69-
}
62+
}

0 commit comments

Comments
 (0)