mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-20 06:51:44 +01:00
initial commit
This commit is contained in:
27
src/module.ts
Normal file
27
src/module.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { dirname, resolve } from 'path'
|
||||
import { defineNuxtModule } from '@nuxt/kit'
|
||||
import fs from 'fs-extra'
|
||||
|
||||
export interface ModuleOptions {}
|
||||
|
||||
export default defineNuxtModule<ModuleOptions>({
|
||||
meta: {
|
||||
name: 'trpc-nuxt',
|
||||
configKey: 'trpc',
|
||||
},
|
||||
defaults: {},
|
||||
async setup(_options, nuxt) {
|
||||
const root = nuxt.options.rootDir
|
||||
const apiPath = resolve(root, 'server/api/trpc/[query].ts')
|
||||
|
||||
await fs.ensureDir(dirname(apiPath))
|
||||
await fs.writeFile(apiPath, `
|
||||
// generated by trpc-nuxt
|
||||
import { createTRPCHandler } from 'trpc-nuxt/handler'
|
||||
import * as functions from '../../fn'
|
||||
export default createTRPCHandler({
|
||||
router: functions.router
|
||||
})
|
||||
`.trimStart())
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user