N
Nuxt5mo ago
lav

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
xibman
xibman5mo ago
You can with a nitro plugin Check this repo
lav
lav5mo ago
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] = myObj
Niza
Niza5mo ago
For readability purposes
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)
})
})
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)
})
})
Want results from more Discord servers?
Add your server