{"id":14971145,"url":"https://github.com/hebilicious/server-block-nuxt","last_synced_at":"2025-04-04T11:08:27.029Z","repository":{"id":180715149,"uuid":"664590879","full_name":"Hebilicious/server-block-nuxt","owner":"Hebilicious","description":"Use \u003cserver\u003e tags in your Nuxt pages components","archived":false,"fork":false,"pushed_at":"2025-04-02T19:30:15.000Z","size":1268,"stargazers_count":115,"open_issues_count":11,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T20:32:06.764Z","etag":null,"topics":["nuxt","nuxt-module","nuxt3","server","sfc","vite","volar"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hebilicious.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["Hebilicious"]}},"created_at":"2023-07-10T10:10:38.000Z","updated_at":"2025-03-31T22:23:58.000Z","dependencies_parsed_at":"2023-10-01T16:23:30.545Z","dependency_job_id":"5eb4b855-21aa-441a-87ac-087970d1c518","html_url":"https://github.com/Hebilicious/server-block-nuxt","commit_stats":{"total_commits":97,"total_committers":2,"mean_commits":48.5,"dds":0.3917525773195877,"last_synced_commit":"b21e2d33e3ff3c4372a1b9e7769a58dc5373b6e3"},"previous_names":["hebilicious/server-block-nuxt"],"tags_count":11,"template":false,"template_full_name":"Hebilicious/nuxt-module-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hebilicious%2Fserver-block-nuxt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hebilicious%2Fserver-block-nuxt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hebilicious%2Fserver-block-nuxt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hebilicious%2Fserver-block-nuxt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hebilicious","download_url":"https://codeload.github.com/Hebilicious/server-block-nuxt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166167,"owners_count":20894654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nuxt","nuxt-module","nuxt3","server","sfc","vite","volar"],"created_at":"2024-09-24T13:44:46.555Z","updated_at":"2025-04-04T11:08:27.015Z","avatar_url":"https://github.com/Hebilicious.png","language":"TypeScript","funding_links":["https://github.com/sponsors/Hebilicious"],"categories":[],"sub_categories":[],"readme":"# Server Block Nuxt\n\n[![CI](https://github.com/Hebilicious/server-block-nuxt/actions/workflows/ci.yaml/badge.svg)](https://github.com/Hebilicious/server-block-nuxt/actions/workflows/ci.yaml)\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![License][license-src]][license-href]\n[![Nuxt][nuxt-src]][nuxt-href]\n\n[npm-version-src]: https://img.shields.io/npm/v/@hebilicious/server-block-nuxt/latest.svg?style=flat\u0026colorA=18181B\u0026colorB=28CF8D\n[npm-version-href]: https://npmjs.com/package/@hebilicious/server-block-nuxt\n[npm-downloads-src]: https://img.shields.io/npm/dt/@hebilicious/server-block-nuxt.svg?style=flat\u0026colorA=18181B\u0026colorB=28CF8D\n[npm-downloads-href]: https://npmjs.com/package/@hebilicious/server-block-nuxt\n[license-src]: https://img.shields.io/npm/l/@hebilicious/server-block-nuxt.svg?style=flat\u0026colorA=18181B\u0026colorB=28CF8D\n[license-href]: https://npmjs.com/package/@hebilicious/server-block-nuxt\n[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js\n[nuxt-href]: https://nuxt.com\n\n\u003cimg width=\"1000\" alt=\"image\" src=\"https://github.com/Hebilicious/server-block-nuxt/assets/13395944/4051eefe-cd83-48cb-a08b-88c451988d10\"\u003e\n\n## 🚀 Welcome to __Server Block Nuxt__!\n\n_🧪 This module is experimental 🧪_\n\nNuxt Module that adds server block supports in your pages components.\n\n```html\n\u003cserver lang=\"ts\"\u003e\u003c/server\u003e\n\u003cscript lang=\"ts\" setup\u003e\u003c/script\u003e\n\u003ctemplate\u003e\u003c/template\u003e\n\u003cstyle\u003e\u003c/style\u003e\n```\n\nYou can think of server block as a convenient way to write API handlers in your pages components.\n\n## 📦 Install\n\nInstall the module and the volar extension :\n\n```bash\nnpm i -D @hebilicious/server-block-nuxt @hebilicious/sfc-server-volar\n```\n\nAdd the module to your Nuxt config :\n\n```ts\nexport default defineNuxtConfig({\n  modules: [\n    \"@hebilicious/server-block-nuxt\"\n  ]\n})\n```\n\nThat's it !\nThe volar extension will be automatically installed by the nuxt module.\n\n## 📖 Usage\n\n- *Server blocks are only available in pages components.*\n\n- *default exports are not available in server blocks. Use named exports.*\n\nAdd a server block in a page component :\n\n```html\n\u003cserver lang=\"ts\"\u003e\nconst message = \"Hello World!!!\"\nconst bye = \"bye!\"\nexport const GET = defineEventHandler(() =\u003e({ message }))\nexport const POST = defineEventHandler(() =\u003e({ message: bye }))\n\u003c/server\u003e\n\n\u003cscript setup lang=\"ts\"\u003e\nconst { data } = useFetch(\"/api/message\")\n\u003c/script\u003e\n\n\u003ctemplate\u003e\n  \u003cdiv\u003e Hello Message, {{ data }} \u003c/div\u003e\n\u003c/template\u003e\n```\n\nThis will generate 2 handlers in `server/.generated/api` :\n\n- GET : `server/.generated/api/message.get.ts`\n- POST : `server/.generated/api/message.post.ts`\n\nAll HTTP methods are supported.\n\n### Custom route\n\nYou can override the default route convention with the `path` attribute  :\n\n```html\n\u003cserver lang=\"ts\" path=\"/not-api/this/is/cool\"\u003e\nexport const GET = defineEventHandler((event) =\u003e {\n  return \"We're here now.\"\n})\n\u003c/server\u003e\n\n\u003cscript setup lang=\"ts\"\u003e\nconst { data } = useFetch(\"/not-api/this/is/cool\")\n\u003c/script\u003e\n\n\u003ctemplate\u003e\n  \u003ch1\u003eHello\u003c/h1\u003e\n  \u003cdiv\u003e {{ data }} \u003c/div\u003e\n\u003c/template\u003e\n```\n\nA `server/.generated/not-api/this/is/cool.get.ts` get handler will be generated.\n\n## 💡 FAQ\n\n**Why `\u003cserver\u003e` and not `\u003cscript server\u003e` ?**\n\n- `\u003cscript server\u003e` causes issues with the current behaviour of additional script tags in SFCs (notably with import/exports)\n- `\u003cserver\u003e` blocks are completely removed from the SFC and don't interfere with `\u003ctemplate\u003e` or `\u003cscript\u003e`, they create a clear boundary.\n- The syntax highlighting work in environments that uses the lang attribute. I would like github support too.\n\n**Why no `defineServerProps` or loaders ?**\n\nYou can combine this with another library such as https://github.com/Hebilicious/form-actions-nuxt if you want to use form actions and loaders.\n\n**Should I commit the generated files to my repository?**\nNo. A `.gitignore` file will be generated for you.\n\n## 📝 TODO\n\n- [x] Integrates with form-actions \u0026 loaders\n- [x] Add useFetch typings\n- [ ] Support multiple server blocks in a single file\n\n## 🫴 Contributing\n\nFeedback, issues and PRs are welcomed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhebilicious%2Fserver-block-nuxt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhebilicious%2Fserver-block-nuxt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhebilicious%2Fserver-block-nuxt/lists"}