brumbrum_brum
brumbrum_brum
Explore posts from servers
TtRPC
Created by brumbrum_brum on 8/24/2024 in #❓-help
Fastify + TRPC on Vercel
I am having trouble hosting a Fastify + TRPC server on Vercel. I have tried two different vercel.json setups, but they both do not work for each reasons:
{
"rewrites": [
{
"source": "/(.*)",
"destination": "/index.js"
}
]
}
{
"rewrites": [
{
"source": "/(.*)",
"destination": "/index.js"
}
]
}
^^^This just shows the built code in the browser, no matter what route I go to.
{
"builds": [{ "src": "./index.js", "use": "@vercel/node" }],
"routes": [{ "src": "/(.*)", "dest": "/" }]
}
{
"builds": [{ "src": "./index.js", "use": "@vercel/node" }],
"routes": [{ "src": "/(.*)", "dest": "/" }]
}
^^This just shows a 404 page from Vercel. This is my index.ts file (Built to index.js):
import { fastifyTRPCPlugin, FastifyTRPCPluginOptions } from "@trpc/server/adapters/fastify";
import { VercelRequest, VercelResponse } from "@vercel/node";
import fastify from "fastify";
import { createContext } from "./context";
import { appRouter, type AppRouter } from "./router";
import dotenv from "dotenv";

export type { AppRouter } from "./router";

dotenv.config();

const server = fastify({});

server.register(fastifyTRPCPlugin, {
prefix: "/",
trpcOptions: {
router: appRouter,
createContext,

onError({ path, error }) {
console.error(`Error in tRPC handler on path '${path}':`, error);
},
} satisfies FastifyTRPCPluginOptions<AppRouter>["trpcOptions"],
});


export default async (req: VercelRequest, res: VercelResponse) => {
await server.ready();
server.server.emit("request", req, res);
};
import { fastifyTRPCPlugin, FastifyTRPCPluginOptions } from "@trpc/server/adapters/fastify";
import { VercelRequest, VercelResponse } from "@vercel/node";
import fastify from "fastify";
import { createContext } from "./context";
import { appRouter, type AppRouter } from "./router";
import dotenv from "dotenv";

export type { AppRouter } from "./router";

dotenv.config();

const server = fastify({});

server.register(fastifyTRPCPlugin, {
prefix: "/",
trpcOptions: {
router: appRouter,
createContext,

onError({ path, error }) {
console.error(`Error in tRPC handler on path '${path}':`, error);
},
} satisfies FastifyTRPCPluginOptions<AppRouter>["trpcOptions"],
});


export default async (req: VercelRequest, res: VercelResponse) => {
await server.ready();
server.server.emit("request", req, res);
};
2 replies
TtRPC
Created by brumbrum_brum on 8/17/2024 in #❓-help
Procedures with paramters.
Is it possible to pass parameters to a procedure in TRPC? I want a procedure that first checks if the user is signed in by default. But then I also want to be able to pass an array of permissions for the user to have, when the actual procedure is used in a route.
9 replies
TtRPC
Created by brumbrum_brum on 6/2/2024 in #❓-help
Generic query type
Does TRPC offer a generic query type? I am thinking of a type where I can control the input/output interface, and then be allowed to pass any query with those interfaces?
2 replies
TtRPC
Created by brumbrum_brum on 3/10/2024 in #❓-help
Not getting "User" type on context.
No description
4 replies