fixing things

This commit is contained in:
Michael Freno
2026-01-07 16:50:10 -05:00
parent 0a0c0e313e
commit 5b0f6dba0f
7 changed files with 123 additions and 48 deletions

View File

@@ -9,7 +9,8 @@ import { blogRouter } from "./routers/blog";
import { gitActivityRouter } from "./routers/git-activity";
import { postHistoryRouter } from "./routers/post-history";
import { infillRouter } from "./routers/infill";
import { createTRPCRouter } from "./utils";
import { createTRPCRouter, createTRPCContext } from "./utils";
import type { H3Event } from "h3";
export const appRouter = createTRPCRouter({
auth: authRouter,
@@ -26,3 +27,13 @@ export const appRouter = createTRPCRouter({
});
export type AppRouter = typeof appRouter;
/**
* Create a server-side caller for tRPC procedures
* This allows calling tRPC procedures directly on the server with proper context
*/
export const createCaller = async (event: H3Event) => {
const apiEvent = { nativeEvent: event, request: event.node.req } as any;
const ctx = await createTRPCContext(apiEvent);
return appRouter.createCaller(ctx);
};

View File

@@ -2,7 +2,7 @@ import { z } from "zod";
import { createTRPCRouter, publicProcedure } from "../utils";
import { env } from "~/env/server";
import { withCacheAndStale } from "~/server/cache";
import { CACHE_CONFIG } from "~/config";
import { CACHE_CONFIG, NETWORK_CONFIG } from "~/config";
import {
fetchWithTimeout,
checkResponse,
@@ -40,7 +40,7 @@ export const gitActivityRouter = createTRPCRouter({
Authorization: `Bearer ${env.GITHUB_API_TOKEN}`,
Accept: "application/vnd.github.v3+json"
},
timeout: 15000 // 15 second timeout
timeout: NETWORK_CONFIG.GITHUB_API_TIMEOUT_MS
}
);
@@ -140,7 +140,7 @@ export const gitActivityRouter = createTRPCRouter({
Authorization: `token ${env.GITEA_TOKEN}`,
Accept: "application/json"
},
timeout: 15000
timeout: NETWORK_CONFIG.GITHUB_API_TIMEOUT_MS
}
);
@@ -229,7 +229,7 @@ export const gitActivityRouter = createTRPCRouter({
getGitHubActivity: publicProcedure.query(async () => {
return withCacheAndStale(
"github-activity",
10 * 60 * 1000,
CACHE_CONFIG.GIT_ACTIVITY_CACHE_TTL_MS,
async () => {
const query = `
query($userName: String!) {
@@ -288,7 +288,7 @@ export const gitActivityRouter = createTRPCRouter({
return contributions;
},
{ maxStaleMs: 24 * 60 * 60 * 1000 }
{ maxStaleMs: CACHE_CONFIG.GIT_ACTIVITY_MAX_STALE_MS }
).catch((error) => {
if (error instanceof NetworkError) {
console.error("GitHub GraphQL API unavailable (network error)");
@@ -308,7 +308,7 @@ export const gitActivityRouter = createTRPCRouter({
getGiteaActivity: publicProcedure.query(async () => {
return withCacheAndStale(
"gitea-activity",
10 * 60 * 1000,
CACHE_CONFIG.GIT_ACTIVITY_CACHE_TTL_MS,
async () => {
const reposResponse = await fetchWithTimeout(
`${env.GITEA_URL}/api/v1/user/repos?limit=100`,
@@ -373,7 +373,7 @@ export const gitActivityRouter = createTRPCRouter({
return contributions;
},
{ maxStaleMs: 24 * 60 * 60 * 1000 }
{ maxStaleMs: CACHE_CONFIG.GIT_ACTIVITY_MAX_STALE_MS }
).catch((error) => {
if (error instanceof NetworkError) {
console.error("Gitea API unavailable (network error)");