{"id":20105934,"url":"https://github.com/markthree/nitro-public-module","last_synced_at":"2025-05-06T09:31:46.048Z","repository":{"id":219392001,"uuid":"748927984","full_name":"markthree/nitro-public-module","owner":"markthree","description":"nitro module for better public compatibility | 对于 nitro 更好的静态资源兼容模块","archived":false,"fork":false,"pushed_at":"2024-12-06T05:54:31.000Z","size":327,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T10:52:12.453Z","etag":null,"topics":["module","nitro","nitropack","node","public"],"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/markthree.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-27T04:08:27.000Z","updated_at":"2024-12-06T07:44:59.000Z","dependencies_parsed_at":"2024-01-27T06:21:00.205Z","dependency_job_id":"60dc4d8e-f31f-4b77-85f6-40acb7ef49ef","html_url":"https://github.com/markthree/nitro-public-module","commit_stats":null,"previous_names":["markthree/nitro-public-module"],"tags_count":15,"template":false,"template_full_name":"markthree/node-lib-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markthree%2Fnitro-public-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markthree%2Fnitro-public-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markthree%2Fnitro-public-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markthree%2Fnitro-public-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markthree","download_url":"https://codeload.github.com/markthree/nitro-public-module/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252657283,"owners_count":21783793,"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":["module","nitro","nitropack","node","public"],"created_at":"2024-11-13T17:48:39.595Z","updated_at":"2025-05-06T09:31:46.043Z","avatar_url":"https://github.com/markthree.png","language":"TypeScript","readme":"# nitro-public-module\n\nnitro module for better public compatibility\n\n\u003cbr /\u003e\n\n## README 🦉\n\n[简体中文](./README_CN.md) | English\n\n\u003cbr /\u003e\n\n## Usage\n\n### install\n\n```shell\nnpm i nitro-public-module -D\n```\n\n### Configuration Module\n\n\u003e nuxt\n\n```ts\n// nuxt.config.ts\nimport nitroPublic from \"nitro-public-module\";\n\nexport default defineNuxtConfig({\n  nitro: {\n    modules: [nitroPublic()],\n  },\n});\n```\n\n\u003e nitro\n\n```ts\n// nitro.config.js\nimport nitroPublic from \"nitro-public-module\";\n\nexport default defineNitroConfig({\n  modules: [nitroPublic()],\n});\n```\n\n\u003cbr /\u003e\n\n### preset\n\n```ts\n// nitro.config.js\nimport nitroPublic from \"nitro-public-module\";\n\nexport default defineNitroConfig({\n  modules: [\n    nitroPublic({\n      // support \"spa\", \"ssg\"，\"fallback\" and false (disable)，default to \"fallback\"\n      preset: \"fallback\",\n    }),\n  ],\n});\n```\n\n#### fallback\n\nSupport rollback of any file in production environment (even if dynamically\nadded to public)\n\n#### spa\n\nAllow you to run `spa` app in public\n\n#### ssg\n\nAllow you to run `ssg` app in public\n\n\u003cbr /\u003e\n\n#### custom\n\n1. disable preset first\n\n```ts\n// nitro.config.js\nimport nitroPublic from \"nitro-public-module\";\n\nexport default defineNitroConfig({\n  modules: [\n    nitroPublic({\n      preset: false,\n    }),\n  ],\n});\n```\n\n2. create custom middleware\n\n```ts\n// middleware/public-fallback.ts\nimport { createPublicFallbackMiddleware } from \"#nitro-public\";\n\nexport default createPublicFallbackMiddleware((withoutSlashPathname) =\u003e {\n  // some logic...\n\n  return {\n    file: \"index.html\", // your file\n    contentType: \"text/html\", // If not set, it will be inferred from the extname of the file\n    withPublicDir: true, // Default to true, help you process the path\n  };\n}, {\n  skipDev: false, // Default to true, skip in development environment\n});\n```\n\n##### virtual\n\nIn addition to providing `createPublicFallbackMiddleware`, `#nitro-public` also\noffers `publicDir` and `serverDir`\n\n```ts\nimport {\n  createPublicFallbackMiddleware,\n  publicDir,\n  serverDir,\n} from \"#nitro-public\";\n```\n\nAll functions are `type safe` and support `development` and `production`\nenvironments (for pure node runtime)\n\n\u003cbr /\u003e\n\n## License\n\nMade with [markthree](https://github.com/markthree)\n\nPublished under [MIT License](./LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkthree%2Fnitro-public-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkthree%2Fnitro-public-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkthree%2Fnitro-public-module/lists"}