Repository patern backend & disadvantage backend in another directory
Hello, I was wondering if it is possible to inject a class instance in my backend.
I would like to make the repository pattern and basically inject my class like we do in the frontend but in the backend. I could not figure out so if if anyone know, please tell me.
Also, is there a disadvantage of moving the backend to another project using express or something at the place of using server directory?
4 Replies
You can with a nitro plugin
Check this repo
GitHub
nuxt-open-fetch/src/runtime/nitro-plugin.ts at main · enkot/nuxt-op...
Generate zero-overhead, typed OpenAPI clients for Nuxt. - enkot/nuxt-open-fetch
I just need to do this:
export default defineNitroPlugin((nitroApp) => {
const clients = useRuntimeConfig().public.openFetch
Object.entries(clients).forEach(([name, client]) => {
// @ts-expect-error - This is a dynamic property
nitroApp[
$${name}
] = createOpenFetch(client)
})
})
?
nitroApp[give it a name] = myObjFor readability purposes