diff --git a/README.md b/README.md index 2916727..701b6ee 100644 --- a/README.md +++ b/README.md @@ -106,15 +106,7 @@ const { data } = useFetch("/not-api/this/is/cool") ``` -This will generate a get handler: `server/.generated/not-api/this/is/cool.get.ts`. - -A `.gitignore` file will be generated for you. Do not commit the generated files in your repository. - -## ⚗ Troubleshooting - -While developing your application, you might encounter a `Page Not Found` error while hitting your extracted server handlers. -To fix this, you can delete the vite cache (usually in `node_modules/.cache/vite`). -If you need more help, feel free to open an issue. +A `server/.generated/not-api/this/is/cool.get.ts` get handler will be generated. ## 💡 FAQ @@ -128,11 +120,14 @@ If you need more help, feel free to open an issue. You can combine this with another library such as https://github.com/Hebilicious/form-actions-nuxt if you want to use form actions and loaders. +**Should I commit the generated files to my repository?** +No. A `.gitignore` file will be generated for you. + ## 📝 TODO - [x] Integrates with form-actions & loaders +- [x] Add useFetch typings - [ ] Support multiple server blocks in a single file -- [ ] Add useFetch typings ## 🫴 Contributing diff --git a/packages/server-block-nuxt/src/module.ts b/packages/server-block-nuxt/src/module.ts index 7f9dc78..c256247 100644 --- a/packages/server-block-nuxt/src/module.ts +++ b/packages/server-block-nuxt/src/module.ts @@ -4,7 +4,7 @@ import { addPlugin, createResolver, defineNuxtModule, useNitro } from "@nuxt/kit import ExtractSFCBlock from "@hebilicious/extract-sfc-block" import { loadFile } from "magicast" -import type { NitroEventHandler } from "nitropack" +import { type NitroEventHandler, writeTypes } from "nitropack" import { SupportedMethods, getRoute, logger, makePathShortener, writeHandlers } from "./utils" export async function* walkFiles(dir: string): AsyncGenerator { @@ -82,6 +82,7 @@ export default defineNuxtModule({ } } // await useNuxt().hooks.callHookParallel("app:data:refresh") @todo find a way to refresh data here + await writeTypes(useNitro()) // Write Nitro handler types for useFetch logger.info("[update]: Nitro Handlers \n", useNitro().options.handlers.map(h => h.route)) } } diff --git a/packages/server-block-nuxt/src/nuxt-types.d.ts b/packages/server-block-nuxt/src/nuxt-types.d.ts deleted file mode 100644 index a7f5408..0000000 --- a/packages/server-block-nuxt/src/nuxt-types.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare module "@nuxt/schema" { - interface PublicRuntimeConfig { - __serverLoaders__: string[] - } -} - -export { } \ No newline at end of file diff --git a/playgrounds/basic/pages/index.vue b/playgrounds/basic/pages/index.vue index 4d94cce..6a60643 100644 --- a/playgrounds/basic/pages/index.vue +++ b/playgrounds/basic/pages/index.vue @@ -1,10 +1,10 @@ - + const message = "Hello World!!!" export const GET = defineEventHandler(() => ({ message }))