{"id":25932556,"url":"https://github.com/applicazza/fastify-nextjs","last_synced_at":"2025-03-04T00:38:10.466Z","repository":{"id":43813902,"uuid":"379059838","full_name":"applicazza/fastify-nextjs","owner":"applicazza","description":"Serve Next.js requests via Fastify","archived":false,"fork":false,"pushed_at":"2023-11-12T03:05:52.000Z","size":1082,"stargazers_count":13,"open_issues_count":3,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-02T11:51:21.812Z","etag":null,"topics":["fastify","nextjs"],"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/applicazza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2021-06-21T20:52:15.000Z","updated_at":"2024-01-14T08:22:00.000Z","dependencies_parsed_at":"2024-10-30T10:16:37.838Z","dependency_job_id":null,"html_url":"https://github.com/applicazza/fastify-nextjs","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"8a009976f2dde44fae94d14978228642d5aa79de"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applicazza%2Ffastify-nextjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applicazza%2Ffastify-nextjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applicazza%2Ffastify-nextjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applicazza%2Ffastify-nextjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/applicazza","download_url":"https://codeload.github.com/applicazza/fastify-nextjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241763765,"owners_count":20016161,"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":["fastify","nextjs"],"created_at":"2025-03-04T00:38:09.829Z","updated_at":"2025-03-04T00:38:10.450Z","avatar_url":"https://github.com/applicazza.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @applicazza/fastify-nextjs\n\n`@applicazza/fastify-nextjs` is a plugin for serving [Next.js](https://nextjs.org) requests\nvia [Fastify](https://github.com/fastify/fastify).\n\n[![npm](https://img.shields.io/npm/v/@applicazza/fastify-nextjs)](https://www.npmjs.com/package/@applicazza/fastify-nextjs) [![codecov](https://codecov.io/gh/applicazza/fastify-nextjs/branch/main/graph/badge.svg?token=CCVDPRT9MT)](https://codecov.io/gh/applicazza/fastify-nextjs)\n\n**This project is yet to reach stable state. You may help by contributing and testing it.**\n\n## Why\n\nOriginal [fastify-nextjs](https://github.com/fastify/fastify-nextjs) doesn't pass response through Fastify's pipeline thus hooks that you may need won't work. This package is using JavaScript's [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) to intercept calls to NodeJs [http.ServerResponse](https://nodejs.org/api/http.html#http_class_http_serverresponse) and pass it to Fastify.\n\n## Usage\n\n### Add dependencies\n\n```shell\nyarn add @applicazza/fastify-nextjs\nyarn add fastify-static\n```\n\n### Disable compression in Next.js (next.config.js)\n\n```js\nmodule.exports = {\n  compress: false,\n};\n```\n\n### Default example\n\n```ts\nimport createFastify from 'fastify';\nimport fastifyNextJs from '@applicazza/fastify-nextjs';\n\nconst dev = process.env.NODE_ENV !== 'production';\n\nconst fastify = createFastify();\n\nfastify.register(fastifyNextJs, {\n    dev,\n});\n\nawait fastify.after();\n\nfastify.passNextJsRequests();\n\nawait fastify.listen(0);\n```\n\n### Extended example\n\n```ts\nimport createFastify from 'fastify';\nimport fastifyNextJs from '@applicazza/fastify-nextjs';\n\nconst dev = process.env.NODE_ENV !== 'production';\n\nconst fastify = createFastify();\n\nfastify.register(fastifyNextJs, {\n    dev,\n});\n\nawait fastify.after();\n\nfastify.passNextJsDataRequests();\nfastify.passNextJsImageRequests();\nif (dev) {\n    fastify.passNextJsDevRequests();\n} else {\n    fastify.passNextJsStaticRequests();\n}\nfastify.passNextJsPageRequests();\n\nawait fastify.listen(0);\n```\n\n### Plugin accepts following options:\n\n```ts\ninterface FastifyNextJsOptions {\n    basePath?: string;\n    dev?: boolean;\n    dir?: string;\n}\n```\n\n### Plugin augments fastify instance with following properties and methods:\n\n```ts\ninterface FastifyNextJsDecoratorArguments {\n  logLevel?: LogLevel;\n}\n\ninterface FastifyInstance {\n    nextJsProxyRequestHandler: (request: FastifyRequest, reply: FastifyReply) =\u003e void;\n    nextJsRawRequestHandler: (request: FastifyRequest, reply: FastifyReply) =\u003e void;\n    nextServer: NextServer;\n    passNextJsRequests: (args?: FastifyNextJsDecoratorArguments) =\u003e void;\n    passNextJsDataRequests: (args?: FastifyNextJsDecoratorArguments) =\u003e void;\n    passNextJsDevRequests: (args?: FastifyNextJsDecoratorArguments) =\u003e void;\n    passNextJsImageRequests: (args?: FastifyNextJsDecoratorArguments) =\u003e void;\n    passNextJsPageRequests: (args?: FastifyNextJsDecoratorArguments) =\u003e void;\n    passNextJsStaticRequests: (args?: FastifyNextJsDecoratorArguments) =\u003e void;\n}\n```\n\n## Building from source\n\n```shell\nyarn build\n```\n\n## Testing\n\n```shell\nyarn test\n```\n\n## License\n\nLicensed under [MIT](./LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapplicazza%2Ffastify-nextjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapplicazza%2Ffastify-nextjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapplicazza%2Ffastify-nextjs/lists"}