Skip to content

Commit

Permalink
fix: edge
Browse files Browse the repository at this point in the history
  • Loading branch information
superhooman committed Oct 24, 2023
1 parent f34a7e3 commit 3aed361
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 124 deletions.
16 changes: 8 additions & 8 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { type Config } from "drizzle-kit";
import { type Config } from 'drizzle-kit';

import { env } from "@src/env.mjs";
import { env } from '@src/env.mjs';

export default {
schema: "./src/server/db/schema.ts",
driver: "mysql2",
dbCredentials: {
connectionString: env.DATABASE_URL
},
tablesFilter: ["goods_*"],
schema: './src/server/db/schema.ts',
driver: 'mysql2',
dbCredentials: {
connectionString: env.DATABASE_URL
},
tablesFilter: ['goods_*'],
} satisfies Config;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
"clsx": "^2.0.0",
"drizzle-orm": "^0.28.5",
"framer-motion": "^10.16.4",
"nanoid": "^5.0.2",
"next": "^13.5.4",
"next-auth": "^4.23.0",
"next-auth": "0.0.0-manual.cfb42ae7",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
Expand Down
87 changes: 34 additions & 53 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export default async function AddItem() {
<AdminAddItemPage />
);
}

export const runtime = 'edge';
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default async function Auth({ params: { id } }: Props) {
return redirect(ROUTES.HOME.get());
}

const [item] = await db.select().from(items).where(eq(items.id, Number(id)));
const [item] = await db.select().from(items).where(eq(items.id, id));

if (!item) {
return redirect(ROUTES.ADMIN.get());
Expand All @@ -35,3 +35,5 @@ export default async function Auth({ params: { id } }: Props) {
<AdminEditItemPage item={item} />
);
}

export const runtime = 'edge';
2 changes: 2 additions & 0 deletions src/app/admin/page.tsx → src/app/(withAuth)/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export default async function Admin() {
<AdminHomePage />
);
}

export const runtime = 'edge';
2 changes: 2 additions & 0 deletions src/app/auth/page.tsx → src/app/(withAuth)/auth/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export default async function Auth() {
<AuthPage />
);
}

export const runtime = 'edge';
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export default async function Auth() {
<ValidatePage />
);
}

export const runtime = 'edge';
13 changes: 13 additions & 0 deletions src/app/(withAuth)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Providers } from './providers';

export default function Layout({
children,
}: {
children: React.ReactNode;
}) {
return (
<Providers>
{children}
</Providers>
);
}
File renamed without changes.
8 changes: 3 additions & 5 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import NextAuth from 'next-auth';
import { handlers } from '@src/server/auth';

import { authOptions } from '@src/server/auth';
export const { GET, POST } = handlers;

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };
export const runtime = 'edge';
2 changes: 2 additions & 0 deletions src/app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ const handler = (req: NextRequest) =>
});

export { handler as GET, handler as POST };

export const runtime = 'edge';
7 changes: 4 additions & 3 deletions src/app/api/upload/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { randomUUID } from 'crypto';

import { NextResponse } from 'next/server';
import { nanoid } from 'nanoid';

import { s3 } from '@src/server/s3';
import { FOLDERS } from '@src/constants/s3';
Expand Down Expand Up @@ -46,7 +45,7 @@ const handler = async (req: Request) => {
}, 400);
}

const id = `${Date.now()}_${randomUUID()}`;
const id = `${Date.now()}_${nanoid(24)}`;

const arrayBuffer = await file.arrayBuffer();

Expand All @@ -73,3 +72,5 @@ const handler = async (req: Request) => {
};

export { handler as POST };

export const runtime = 'edge';
8 changes: 2 additions & 6 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { TRPCReactProvider } from '@src/trpc/react';
import { DOMAIN_NAME, ROUTES } from '@src/constants/routes';
import { Toaster } from '@src/components/Toaster';

import { Providers } from './providers';

const inter = Inter({
subsets: ['latin'],
});
Expand Down Expand Up @@ -40,10 +38,8 @@ export default function RootLayout({
return (
<html lang="en">
<body className={inter.className}>
<Providers>
<TRPCReactProvider headers={headers()}>{children}</TRPCReactProvider>
<Toaster />
</Providers>
<TRPCReactProvider headers={headers()}>{children}</TRPCReactProvider>
<Toaster />
</body>
</html>
);
Expand Down
2 changes: 2 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export default async function Home() {
</Container>
);
}

export const runtime = 'edge';
2 changes: 1 addition & 1 deletion src/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const ROUTES = {
ADMIN: new Route('/admin'),

ADD_ITEM: new Route('/admin/add'),
EDIT_ITEM: new Route<{ id: number }>('/admin/edit/:id'),
EDIT_ITEM: new Route<{ id: string }>('/admin/edit/:id'),

API: {
UPLOAD: new Route('/api/upload'),
Expand Down
32 changes: 7 additions & 25 deletions src/server/api/routers/admin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DeleteObjectCommand } from '@aws-sdk/client-s3';
import { z } from 'zod';
import { eq } from 'drizzle-orm';
import { nanoid } from 'nanoid';

import { FOLDERS } from '@src/constants/s3';
import { itemSchema } from '@src/schemas/item';
Expand Down Expand Up @@ -30,42 +31,23 @@ export const adminRouter = createTRPCRouter({
.mutation(async ({ ctx, input }) => {
const { user } = ctx.session;

// const item = await ctx.prisma.item.create({
// data: {
// ...input,
// user: { connect: { id: user.id } },
// },
// });
const id = nanoid(24);

const item = await ctx.db.insert(items).values({
await ctx.db.insert(items).values({
id,
...input,
createdById: user.id,
});

console.log({ item });

return item;
}),
editItem: protectedProcedure
.input(z.object({
id: z.number(),
id: z.string(),
data: itemSchema,
}))
.mutation(async ({ ctx, input: { id, data } }) => {
// const item = await ctx.prisma.item.update({
// where: { id },
// data: {
// ...data,
// },
// });

const item = await ctx.db.update(items).set(data).where(eq(items.id, id));

return item;
}),
.mutation(({ ctx, input: { id, data } }) => ctx.db.update(items).set(data).where(eq(items.id, id))),
removeItem: protectedProcedure
.input(z.object({
id: z.number(),
id: z.string(),
}))
.mutation(async ({ ctx, input: { id } }) => {
await ctx.db.delete(items).where(eq(items.id, id));
Expand Down
Loading

0 comments on commit 3aed361

Please sign in to comment.