Skip to content

Commit d392e0b

Browse files
committed
add draft mode enable/disable routes and newsletter subscription endpoint
1 parent 0345267 commit d392e0b

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { draftMode } from "next/headers";
2+
import { NextRequest, NextResponse } from "next/server";
3+
4+
export async function GET(request: NextRequest) {
5+
(await draftMode()).disable();
6+
return NextResponse.redirect(new URL("/", request.url));
7+
}

app/api/draft-mode/enable/route.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineEnableDraftMode } from "next-sanity/draft-mode";
2+
import { client } from "@/sanity/lib/client";
3+
import { token } from "@/sanity/lib/token";
4+
5+
export const { GET } = defineEnableDraftMode({
6+
client: client.withConfig({ token }),
7+
});

app/api/newsletter/route.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Resend } from "resend";
2+
3+
const resend = new Resend(process.env.RESEND_API_KEY);
4+
5+
export const POST = async (request: Request) => {
6+
const { email } = await request.json();
7+
8+
// Create contact
9+
try {
10+
resend.contacts.create({
11+
email,
12+
unsubscribed: false,
13+
audienceId: process.env.RESEND_AUDIENCE_ID!,
14+
});
15+
16+
return Response.json({ success: true });
17+
} catch (error: any) {
18+
return Response.json(
19+
{ error: "Error subscribing to updates" },
20+
{ status: 400 }
21+
);
22+
}
23+
};

app/studio/[[...tool]]/page.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* This route is responsible for the built-in authoring environment using Sanity Studio.
3+
* All routes under your studio path is handled by this file using Next.js' catch-all routes:
4+
* https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes
5+
*
6+
* You can learn more about the next-sanity package here:
7+
* https://github.com/sanity-io/next-sanity
8+
*/
9+
10+
import { NextStudio } from 'next-sanity/studio'
11+
import config from '../../../sanity.config'
12+
13+
export const dynamic = 'force-static'
14+
15+
export { metadata, viewport } from 'next-sanity/studio'
16+
17+
export default function StudioPage() {
18+
return <NextStudio config={config} />
19+
}

0 commit comments

Comments
 (0)