got some server hydration I think

This commit is contained in:
2024-11-08 15:16:53 -07:00
parent 011c28f0fd
commit 6fd5053ac5
20 changed files with 568 additions and 244 deletions

View File

@@ -11,11 +11,12 @@ export default function TrpcProvider({
children: React.ReactNode;
}) {
// NOTE: Your production URL environment variable may be different
const url = "/api/trpc";
// process.env.NEXT_PUBLIC_APP_DOMAIN &&
// !process.env.NEXT_PUBLIC_APP_DOMAIN.includes("localhost")
// ? `https://www.${process.env.NEXT_PUBLIC_APP_DOMAIN}/api/trpc/`
// : "http://localhost:3000/api/trpc/";
const url = "http://localhost:3000/api/trpc/"
//"/api/trpc";
// process.env.NEXT_PUBLIC_APP_DOMAIN &&
// !process.env.NEXT_PUBLIC_APP_DOMAIN.includes("localhost")
// ? `https://www.${process.env.NEXT_PUBLIC_APP_DOMAIN}/api/trpc/`
// : "http://localhost:3000/api/trpc/";
const [trpcClient] = useState(() =>
trpc.createClient({

View File

@@ -2,6 +2,7 @@ import { createTrpcContext } from "../context";
import publicProcedure from "../procedures/public";
import { createCallerFactory, router } from "../trpc";
import { assignmentRouter } from "./assignmentRouter";
import { lectureRouter } from "./lectureRouter";
export const helloRouter = router({
sayHello: publicProcedure.query(() => {
@@ -14,6 +15,7 @@ export const helloRouter = router({
export const trpcAppRouter = router({
hello: helloRouter,
assignment: assignmentRouter,
lectures: lectureRouter,
});
export const createCaller = createCallerFactory(trpcAppRouter);

View File

@@ -0,0 +1,15 @@
import { z } from "zod";
import publicProcedure from "../procedures/public";
import { router } from "../trpc";
import { getLectures } from "@/services/fileStorage/lectureFileStorageService";
export const lectureRouter = router({
getLectures: publicProcedure
.input(z.object({
courseName: z.string()
}))
.query(async ({input: {courseName}}) => {
return await getLectures(courseName)
})
})

View File

@@ -1,4 +1,50 @@
import { createTRPCReact } from "@trpc/react-query";
import { createTRPCReact, httpBatchLink } from "@trpc/react-query";
import { createTRPCNext } from "@trpc/next";
import { ssrPrepass } from '@trpc/next/ssrPrepass';
import { AppRouter } from "./router/app";
import superjson from "superjson";
export const trpc = createTRPCReact<AppRouter>();
// export const trpc = createTRPCNext<AppRouter>({
// ssr: true,
// ssrPrepass,
// transformer: superjson,
// config(opts) {
// const { ctx } = opts;
// if (typeof window !== "undefined") {
// // during client requests
// return {
// links: [
// httpBatchLink({
// url: "/api/trpc",
// transformer: superjson,
// }),
// ],
// };
// }
// return {
// links: [
// httpBatchLink({
// transformer: superjson,
// // The server needs to know your app's full url
// url: `http://localhost:3000/api/trpc`,
// /**
// * Set custom request headers on every request from tRPC
// * @see https://trpc.io/docs/v10/header
// */
// headers() {
// if (!ctx?.req?.headers) {
// return {};
// }
// // To use SSR properly, you need to forward client headers to the server
// // This is so you can pass through things like cookies when we're server-side rendering
// return {
// cookie: ctx.req.headers.cookie,
// };
// },
// }),
// ],
// };
// },
// });
// export const trpcClient = trpc.createClient({ links: [] }); //server only?