From 2ea95229408e34ab5ed6faaa4f90768372825fb6 Mon Sep 17 00:00:00 2001 From: ditiqi Date: Tue, 27 May 2025 08:56:38 +0800 Subject: [PATCH] add --- apps/backend/src/index.ts | 80 +++++++++++------------ apps/backend/src/router.ts | 8 +++ apps/backend/src/trpc.ts | 16 ++--- apps/backend/tsconfig.json | 19 +++--- apps/web/app/page.tsx | 2 + apps/web/components/providers.tsx | 21 +++--- dockers/storage-minio.yml | 8 +-- packages/client/src/api/hooks/useHello.ts | 1 - 8 files changed, 79 insertions(+), 76 deletions(-) create mode 100644 apps/backend/src/router.ts diff --git a/apps/backend/src/index.ts b/apps/backend/src/index.ts index 3550582..604d5b1 100644 --- a/apps/backend/src/index.ts +++ b/apps/backend/src/index.ts @@ -1,50 +1,50 @@ -import { Hono } from 'hono' -import { logger } from 'hono/logger' -import { contextStorage, getContext } from 'hono/context-storage' -import { prettyJSON } from 'hono/pretty-json' +import { Hono } from 'hono'; +import { logger } from 'hono/logger'; +import { contextStorage, getContext } from 'hono/context-storage'; +import { prettyJSON } from 'hono/pretty-json'; -import { trpcServer } from '@hono/trpc-server' -import { appRouter } from './trpc' -import Redis from 'ioredis' -import redis from './redis' -import minioClient from './minio' -import { Client } from 'minio' -import oidc from './oidc/provider' +import { trpcServer } from '@hono/trpc-server'; +import { appRouter } from './router'; +import Redis from 'ioredis'; +import redis from './redis'; +import minioClient from './minio'; +import { Client } from 'minio'; +import oidc from './oidc/provider'; type Env = { - Variables: { - redis: Redis - minio: Client - } -} + Variables: { + redis: Redis; + minio: Client; + }; +}; -const app = new Hono() +const app = new Hono(); app.use('*', async (c, next) => { - c.set('redis', redis) - c.set('minio', minioClient) - await next() -}) -app.use('*', async (c, next) => { - c.set('redis', redis); - await next(); + c.set('redis', redis); + c.set('minio', minioClient); + await next(); }); -app.use(contextStorage()) -app.use(prettyJSON()) // With options: prettyJSON({ space: 4 }) -app.use(logger()) +app.use('*', async (c, next) => { + c.set('redis', redis); + await next(); +}); +app.use(contextStorage()); +app.use(prettyJSON()); // With options: prettyJSON({ space: 4 }) +app.use(logger()); app.use( - '/trpc/*', - trpcServer({ - router: appRouter, - }) -) + '/trpc/*', + trpcServer({ + router: appRouter, + }), +); app.get('/', (c) => { - return c.text('Hello Hono!') -}) + return c.text('Hello Hono!'); +}); app.use('/oidc/*', async (c, next) => { - // @ts-ignore - await oidc.callback(c.req.raw, c.res.raw) - // return void 也可以 - return -}) -export default app + // @ts-ignore + await oidc.callback(c.req.raw, c.res.raw); + // return void 也可以 + return; +}); +export default app; diff --git a/apps/backend/src/router.ts b/apps/backend/src/router.ts new file mode 100644 index 0000000..26f009c --- /dev/null +++ b/apps/backend/src/router.ts @@ -0,0 +1,8 @@ +import { router } from './trpc'; +import { userRouter } from './user/user.trpc'; + +export const appRouter = router({ + user: userRouter, +}); + +export type AppRouter = typeof appRouter; diff --git a/apps/backend/src/trpc.ts b/apps/backend/src/trpc.ts index 9e751a2..32bd49e 100644 --- a/apps/backend/src/trpc.ts +++ b/apps/backend/src/trpc.ts @@ -1,14 +1,6 @@ -import { z } from 'zod' -import { initTRPC } from '@trpc/server' -import { userRouter } from './user/user.trpc' +import { initTRPC } from '@trpc/server'; -const t = initTRPC.create() +const t = initTRPC.create(); -export const publicProcedure = t.procedure -export const router = t.router - -export const appRouter = router({ - user: userRouter -}) - -export type AppRouter = typeof appRouter \ No newline at end of file +export const publicProcedure = t.procedure; +export const router = t.router; diff --git a/apps/backend/tsconfig.json b/apps/backend/tsconfig.json index 55a8094..53412b3 100644 --- a/apps/backend/tsconfig.json +++ b/apps/backend/tsconfig.json @@ -1,11 +1,10 @@ { - "extends": "@repo/typescript-config/hono.json", - "compilerOptions": { - "moduleResolution": "bundler", - "paths": { - "@/*": ["./*"], - "@repo/db/*": ["../../packages/db/src/*"], - }, - - } -} \ No newline at end of file + "extends": "@repo/typescript-config/hono.json", + "compilerOptions": { + "moduleResolution": "bundler", + "paths": { + "@/*": ["./*"], + "@repo/db/*": ["../../packages/db/src/*"] + } + } +} diff --git a/apps/web/app/page.tsx b/apps/web/app/page.tsx index b76f59b..eb60d59 100644 --- a/apps/web/app/page.tsx +++ b/apps/web/app/page.tsx @@ -1,5 +1,7 @@ 'use client'; +import { useTRPC } from '@repo/client'; + // import { api } from '@repo/client'; // import { Button } from '@repo/ui/components/button'; // import { useState } from 'react'; diff --git a/apps/web/components/providers.tsx b/apps/web/components/providers.tsx index 49ecbf4..4fb33d2 100644 --- a/apps/web/components/providers.tsx +++ b/apps/web/components/providers.tsx @@ -2,17 +2,20 @@ import * as React from 'react'; import { ThemeProvider as NextThemesProvider } from 'next-themes'; +import QueryProvider from '@/providers/query-provider'; export function Providers({ children }: { children: React.ReactNode }) { return ( - - {children} - + + + {children} + + ); } diff --git a/dockers/storage-minio.yml b/dockers/storage-minio.yml index 9b137b0..2ca3c74 100644 --- a/dockers/storage-minio.yml +++ b/dockers/storage-minio.yml @@ -1,11 +1,11 @@ services: minio: - image: minio/minio:${MINIO_VERSION:-RELEASE.2024-04-22T22-12-26Z} + image: minio/minio:${MINIO_VERSION:-RELEASE.2024-04-18T19-09-19Z} container_name: minio restart: always ports: - - "9000:9000" - - "9001:9001" + - '9000:9000' + - '9001:9001' networks: - nice-net environment: @@ -17,7 +17,7 @@ services: target: /data command: server /data --console-address ":9001" healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] + test: ['CMD', 'curl', '-f', 'http://localhost:9000/minio/health/live'] interval: 30s timeout: 20s retries: 3 diff --git a/packages/client/src/api/hooks/useHello.ts b/packages/client/src/api/hooks/useHello.ts index 00b5155..a2fc1a2 100644 --- a/packages/client/src/api/hooks/useHello.ts +++ b/packages/client/src/api/hooks/useHello.ts @@ -1,4 +1,3 @@ -import { api } from '../trpc'; export function useHello() { return {