Skip to content

Commit

Permalink
feat: edge runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
RUNFUNRUN committed Aug 2, 2024
1 parent 1237545 commit 2d90277
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 36 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"dependencies": {
"@auth/prisma-adapter": "^2.4.2",
"@hookform/resolvers": "^3.9.0",
"@neondatabase/serverless": "^0.9.4",
"@next/third-parties": "^14.2.5",
"@prisma/adapter-neon": "^5.17.0",
"@prisma/client": "^5.17.0",
"@radix-ui/react-avatar": "^1.1.0",
"@radix-ui/react-dialog": "^1.1.1",
Expand Down
2 changes: 2 additions & 0 deletions src/app/(default)/community/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const runtime = 'edge';

const Page = ({ params }: { params: { slug: string } }) => {
return <div>{params.slug}</div>;
};
Expand Down
39 changes: 5 additions & 34 deletions src/app/(default)/community/page.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,19 @@
import { auth } from '@/auth';
import { ArtCards } from '@/components/art-cards';
import type { Metadata } from 'next';
import { Suspense } from 'react';

const SessionData = async () => {
const session = await auth();
if (session?.user) {
return (
<div className='flex flex-col gap-4 p-4 w-full rounded-md border-2'>
<h2 className='text-xl font-bold'>Current Session Data</h2>
{Object.keys(session.user).length > 3 ? (
<p>
In this example, the whole session object is passed to the page,
including the raw user object. Our recommendation is to{' '}
<em>only pass the necessary fields</em> to the page, as the raw user
object may contain sensitive information.
</p>
) : (
<p>
In this example, only some fields in the user object is passed to
the page to avoid exposing sensitive information.
</p>
)}
<div className='flex flex-col rounded-md '>
<div className='p-4 font-bold rounded-t-md'>Session</div>
<pre className='py-6 px-4 whitespace-pre-wrap break-all'>
{JSON.stringify(session, null, 2)}
</pre>
</div>
</div>
);
}
export const runtime = 'edge';

return (
<p className='p-4 w-full rounded-md border-2'>
No session data, please <em>Sign In</em> first.
</p>
);
const Contents = async () => {
return <ArtCards />;
};

const Page = () => {
return (
<div className='container'>
<Suspense>
<SessionData />
<Contents />
</Suspense>
</div>
);
Expand Down
2 changes: 2 additions & 0 deletions src/app/(default)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { OpinionBox } from '@/components/opinion-box';
import { OekakiChat } from './_components/oekaki-chat';
import { Share } from './_components/share';

export const runtime = 'edge';

const Home = () => {
return (
<>
Expand Down
2 changes: 2 additions & 0 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const runtime = 'edge';

export { GET, POST } from '@/auth';
2 changes: 2 additions & 0 deletions src/app/api/share/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { ShareArtResponse } from '@/types';
import { flattenArray } from '@/utils';
import { NextResponse } from 'next/server';

export const runtime = 'edge';

export const POST = auth(async (req) => {
const session = req.auth;
if (!session) {
Expand Down
2 changes: 1 addition & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { prisma } from '@/client';
import { prisma } from './client';
import { PrismaAdapter } from '@auth/prisma-adapter';
import NextAuth from 'next-auth';
import authConfig from './auth.config';
Expand Down
6 changes: 5 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { PrismaClient } from '@prisma/client';
import { PrismaNeon } from '@prisma/adapter-neon';
import { Pool } from '@neondatabase/serverless';

const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };

export const prisma = globalForPrisma.prisma || new PrismaClient();
const neon = new Pool({ connectionString: process.env.POSTGRES_PRISMA_URL });
const adapter = new PrismaNeon(neon);
export const prisma = globalForPrisma.prisma || new PrismaClient({ adapter });

if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;

0 comments on commit 2d90277

Please sign in to comment.