mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: init trpc
This commit is contained in:
1 parent
8cc006e3a4
commit
6326b84a60
6 files changed
+44
-1
No files matched your search
@@ -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', () => {
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in new issue
Block a user