Fixed trpc routing

This commit is contained in:
Umar Adilov 2026-01-08 22:27:58 +05:00
parent 67141fd00e
commit bd87e2ae3d
2 changed files with 5 additions and 5 deletions

View File

@ -26,7 +26,7 @@ function getBaseUrl() {
export const trpcClient: TRPCClient<AppRouter> = trpc.createClient({ export const trpcClient: TRPCClient<AppRouter> = trpc.createClient({
links: [ links: [
httpBatchLink({ httpBatchLink({
url: `${getBaseUrl()}/trpc`, url: `${getBaseUrl()}/api/trpc`,
// Optional: add headers, credentials, etc. // Optional: add headers, credentials, etc.
// headers() { // headers() {
// return { // return {

View File

@ -19,19 +19,19 @@ app.use(
); );
// Health check endpoint // Health check endpoint
app.get("/health", (_req, res) => { app.get("/api/health", (_req, res) => {
res.json({ status: "ok", timestamp: new Date().toISOString() }); res.json({ status: "ok", timestamp: new Date().toISOString() });
}); });
// tRPC middleware // tRPC middleware
app.use( app.use(
"/trpc", "/api/trpc",
(req, res, next) => { (req, res, next) => {
// Handle root path access with a friendly message instead of a tRPC error // Handle root path access with a friendly message instead of a tRPC error
if (req.path === "/" || req.path === "") { if (req.path === "/" || req.path === "") {
return res.json({ return res.json({
message: "TaylorDB tRPC server is running!", message: "TaylorDB tRPC server is running!",
health: `http://${req.headers.host}/trpc/health`, health: `http://${req.headers.host}/api/trpc/health`,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
}); });
} }
@ -46,5 +46,5 @@ app.use(
// Start server // Start server
app.listen(PORT, () => { app.listen(PORT, () => {
console.log(`🚀 Server running on http://localhost:${PORT}`); console.log(`🚀 Server running on http://localhost:${PORT}`);
console.log(`📡 tRPC endpoint: http://localhost:${PORT}/trpc`); console.log(`📡 tRPC endpoint: http://localhost:${PORT}/api/trpc`);
}); });