feat: init trpc

This commit is contained in:
Justin Lin committed 2025-04-16 15:27:00 +08:00
1 parent 8cc006e3a4
commit 6326b84a60
6 files changed
+44 -1

No files matched your search

+3 -1
View File
@@ -17,6 +17,7 @@
"@linux-odyssey/file-graph": "*",
"@linux-odyssey/models": "*",
"@linux-odyssey/utils": "*",
"@trpc/server": "^11.1.0",
"bcrypt": "^5.1.1",
"commander": "^11.0.0",
"connect-mongo": "^5.0.0",
@@ -44,7 +45,8 @@
"swagger-ui-express": "^5.0.0",
"validator": "^13.11.0",
"winston": "^3.11.0",
"yaml": "^2.3.1"
"yaml": "^2.3.1",
"zod": "^3.24.2"
},
"devDependencies": {
"@swc/core": "^1.4.2",
+9
View File
@@ -4,6 +4,7 @@ import http from 'http'
import YAML from 'yaml'
import swaggerUI from 'swagger-ui-express'
import passport from 'passport'
import * as trpcExpress from '@trpc/server/adapters/express'
import connectDB from '@linux-odyssey/models'
import './auth/passport.js'
@@ -17,6 +18,7 @@ import sessionMiddleware from './middleware/session.js'
import expiryRemovalScheduler from './containers/expiryChecker.js'
import setupTest from './utils/setupTest.js'
import logger from './utils/logger.js'
import { appRouter } from './routers/index.js'
async function main() {
if (!config.secret) {
@@ -70,6 +72,13 @@ async function main() {
})
app.use('/api/v1', apiRouter)
app.use(
'/trpc',
trpcExpress.createExpressMiddleware({
router: appRouter,
// createContext,
})
)
app.use(errorHandler)
server.listen(config.port, '0.0.0.0', () => {
+11
View File
@@ -0,0 +1,11 @@
import { router, publicProcedure } from '../trpc.js'
export const appRouter = router({
userList: publicProcedure.query(async () => {
// Retrieve users from a datasource, this is an imaginary database
return 'hello'
}),
})
// Export type router type signature,
// NOT the router itself.
export type AppRouter = typeof appRouter
+11
View File
@@ -0,0 +1,11 @@
import { initTRPC } from '@trpc/server'
/**
* Initialization of tRPC backend
* Should be done only once per backend!
*/
const t = initTRPC.create()
/**
* Export reusable router and procedure helpers
* that can be used throughout the router
*/
export const { router, procedure: publicProcedure } = t
View File
Whitespace-only changes.
+10
View File
@@ -1711,6 +1711,11 @@
lz-string "^1.5.0"
pretty-format "^27.0.2"
"@trpc/server@^11.1.0":
version "11.1.0"
resolved "https://registry.yarnpkg.com/@trpc/server/-/server-11.1.0.tgz#8169fa8b944beddf65a95f376d4afea5732be254"
integrity sha512-uAJ7ikejeujVkf53XFJ/0W8nr7bDjul+Szk5Rsepq97Hb/WS1RkRXdyX4KqAyCE9b1vDFCJVJwSxiIZdRtbTZQ==
"@tsconfig/node10@^1.0.7":
version "1.0.9"
resolved "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz"
@@ -9780,3 +9785,8 @@ zod@^3.23.8:
version "3.23.8"
resolved "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz"
integrity sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==
zod@^3.24.2:
version "3.24.2"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.24.2.tgz#8efa74126287c675e92f46871cfc8d15c34372b3"
integrity sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==