Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
marcolivierbouch committed Nov 27, 2024
1 parent 1063a90 commit 57351ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions apps/configuration-api/app/api/assign/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function GET(req: Request) {
} catch (error) {
console.error(error);

return new Response('Internal Server Error', { status: 500 });
return NextResponse.json('Internal Server Error', { status: 500 });
}
}

Expand Down Expand Up @@ -76,14 +76,14 @@ export async function PATCH(req: Request) {
console.log(createResponse);
}

return new Response('created', { status: 201 });
return NextResponse.json('created', { status: 201 });
} catch (error) {
console.log(error);
if (error instanceof z.ZodError) {
return new Response(JSON.stringify(error.issues), { status: 422 });
return NextResponse.json(JSON.stringify(error.issues), { status: 422 });
}

return new Response(null, { status: 500 });
return NextResponse.json(null, { status: 500 });
}
}

Expand Down
7 changes: 3 additions & 4 deletions apps/configuration-api/app/api/domain/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
addDomainToVercel,
getDomains,
getAllItemsFromEdgeConfig,
} from '@customdomainready/sdk';
import { NextResponse } from 'next/server';

Expand All @@ -26,7 +25,7 @@ export async function POST(req: Request) {
process.env.AUTH_BEARER_TOKEN,
);
if (existingDomains.domains.some((d: any) => d.name === domain)) {
return new Response('Domain already exists', { status: 200 });
return NextResponse.json('Domain already exists', { status: 200 });
}

const response = await addDomainToVercel(
Expand All @@ -37,7 +36,7 @@ export async function POST(req: Request) {
);

if (response.error) {
return new Response(response.error.message, { status: 400 });
return NextResponse.json(response.error.message, { status: 400 });
}

return NextResponse.json({
Expand All @@ -46,6 +45,6 @@ export async function POST(req: Request) {
} catch (error) {
console.error(error);

return new Response('Internal Server Error', { status: 500 });
return NextResponse.json('Internal Server Error', { status: 500 });
}
}
12 changes: 8 additions & 4 deletions apps/configuration-api/components/custom-domain-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Trash2, RefreshCw } from 'lucide-react';
import { getDomainResponse } from '@customdomainready/sdk';

interface DomainConfig {
id: string;
Expand All @@ -25,7 +26,6 @@ export default function CustomDomainConfig() {
try {
const response = await fetch('/api/assign');
const data = await response.json();
console.log(data);
setConfigs(
data.response.map((domain: any) => ({
id: domain.id,
Expand Down Expand Up @@ -61,6 +61,9 @@ export default function CustomDomainConfig() {
if (!domainResponse.ok) {
throw new Error('Failed to add domain');
}

const response = await domainResponse.json()
alert(JSON.stringify(response))
}

const aliasResponse = await fetch('/api/assign', {
Expand All @@ -74,7 +77,7 @@ export default function CustomDomainConfig() {
destination: newConfig.destinationPath,
}),
});

if (!aliasResponse.ok) {
throw new Error('Failed to create alias');
}
Expand All @@ -91,6 +94,7 @@ export default function CustomDomainConfig() {
console.error('Error adding domain and alias:', error);
}
};

const removeConfig = async (
sourceDomain: string,
slug: string,
Expand Down Expand Up @@ -158,7 +162,7 @@ export default function CustomDomainConfig() {
onChange={e =>
setNewConfig({ ...newConfig, slug: e.target.value })
}
placeholder="blog"
placeholder="/blog"
/>
</div>
<div>
Expand All @@ -172,7 +176,7 @@ export default function CustomDomainConfig() {
destinationPath: e.target.value,
})
}
placeholder="/posts"
placeholder="https://www.mywebsite.com/posts"
/>
</div>
</div>
Expand Down

0 comments on commit 57351ac

Please sign in to comment.