const server = fastify({
maxParamLength: 5000,
});
await server.register(cors, {
origin: (origin, cb) => {
console.log(`CORS origin check: ${origin}`);
cb(null, true);
// const hostname = new URL(origin).hostname
// if(hostname === "localhost"){
// // Request from localhost will pass
// return
// }
// // Generate an error on other origins, disabling access
// cb(new Error("Not allowed"), false)
},
methods: ["GET", "POST", "OPTIONS"],
allowedHeaders: ["Content-Type", "Authorization", "Accept"],
credentials: true,
preflightContinue: false,
optionsSuccessStatus: 204,
});
server.register(fastifyTRPCPlugin, {
prefix: "/trpc",
trpcOptions: {
router: appRouter,
onError({ path, error }) {
// report to error monitoring
console.error(`Error in tRPC handler on path '${path}':`, error);
},
} satisfies FastifyTRPCPluginOptions<AppRouter>["trpcOptions"],
});
const server = fastify({
maxParamLength: 5000,
});
await server.register(cors, {
origin: (origin, cb) => {
console.log(`CORS origin check: ${origin}`);
cb(null, true);
// const hostname = new URL(origin).hostname
// if(hostname === "localhost"){
// // Request from localhost will pass
// return
// }
// // Generate an error on other origins, disabling access
// cb(new Error("Not allowed"), false)
},
methods: ["GET", "POST", "OPTIONS"],
allowedHeaders: ["Content-Type", "Authorization", "Accept"],
credentials: true,
preflightContinue: false,
optionsSuccessStatus: 204,
});
server.register(fastifyTRPCPlugin, {
prefix: "/trpc",
trpcOptions: {
router: appRouter,
onError({ path, error }) {
// report to error monitoring
console.error(`Error in tRPC handler on path '${path}':`, error);
},
} satisfies FastifyTRPCPluginOptions<AppRouter>["trpcOptions"],
});