{"id":20083648,"url":"https://github.com/marko-js/fastify","last_synced_at":"2026-04-02T15:58:05.548Z","repository":{"id":45193184,"uuid":"342035319","full_name":"marko-js/fastify","owner":"marko-js","description":"Render Marko templates in a Fastify application.","archived":false,"fork":false,"pushed_at":"2022-06-22T15:39:24.000Z","size":704,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-26T00:04:06.308Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/marko-js.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-24T21:04:42.000Z","updated_at":"2025-02-26T12:31:02.000Z","dependencies_parsed_at":"2022-08-30T08:31:01.419Z","dependency_job_id":null,"html_url":"https://github.com/marko-js/fastify","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marko-js%2Ffastify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marko-js%2Ffastify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marko-js%2Ffastify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marko-js%2Ffastify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marko-js","download_url":"https://codeload.github.com/marko-js/fastify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252604281,"owners_count":21775077,"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":[],"created_at":"2024-11-13T15:48:12.746Z","updated_at":"2026-04-02T15:58:05.512Z","avatar_url":"https://github.com/marko-js.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003c!-- Logo --\u003e\n  \u003cbr/\u003e\n  @marko/fastify\n\t\u003cbr/\u003e\n\n  \u003c!-- Language --\u003e\n  \u003ca href=\"http://typescriptlang.org\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/%3C%2F%3E-typescript-blue.svg\" alt=\"TypeScript\"/\u003e\n  \u003c/a\u003e\n  \u003c!-- Format --\u003e\n  \u003ca href=\"https://github.com/prettier/prettier\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/styled_with-prettier-ff69b4.svg\" alt=\"Styled with prettier\"/\u003e\n  \u003c/a\u003e\n  \u003c!-- CI --\u003e\n  \u003ca href=\"https://github.com/marko-js/fastify/actions/workflows/ci.yml\"\u003e\n    \u003cimg src=\"https://github.com/marko-js/fastify/actions/workflows/ci.yml/badge.svg\" alt=\"Build status\"/\u003e\n  \u003c/a\u003e\n  \u003c!-- Coverage --\u003e\n  \u003ca href=\"https://codecov.io/gh/marko-js/fastify\"\u003e\n    \u003cimg src=\"https://codecov.io/gh/marko-js/fastify/branch/main/graph/badge.svg?token=3VFGDEC7G7\"/\u003e\n  \u003c/a\u003e\n  \u003c!-- NPM Version --\u003e\n  \u003ca href=\"https://npmjs.org/package/@marko/fastify\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/@marko/fastify.svg\" alt=\"NPM Version\"/\u003e\n  \u003c/a\u003e\n  \u003c!-- Downloads --\u003e\n  \u003ca href=\"https://npmjs.org/package/@marko/fastify\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dm/@marko/fastify.svg\" alt=\"Downloads\"/\u003e\n  \u003c/a\u003e\n\u003c/h1\u003e\n\nRender [Marko](https://markojs.com/) templates in a [`Fastify`](https://www.fastify.io/) application.\n\n# Installation\n\n```console\nnpm install @marko/fastify\n```\n\n# Examples\n\n## Setup\n\n\u003e Note: the example below assumes that you've configured the environment to handle `.marko` files.\n\u003e This means using the require hook (`@marko/compiler/register`) or a bundler like `webpack`, `vite`, etc.\n\u003e We recommend using `npm init marko -- --template vite-fastify` for a more complete example!\n\n```javascript\nimport fastify from \"fastify\";\nimport markoPlugin from \"@marko/fastify\";\nimport Template from \"./template.marko\";\n\nconst app = fastify();\n\napp.register(markoPlugin);\n\napp.get(\"/\", (request, reply) =\u003e {\n  // Streams Marko template into the response.\n  // Forwards errors into fa error handler.\n  reply.marko(Template, { hello: \"world\" });\n});\n```\n\n## $global / out.global\n\nWhen calling `reply.marko` the [`input.$global`](https://markojs.com/docs/rendering/#global-data) is automatically merged with `app.locals` and `reply.locals` (both added by this plugin). This makes it easy to set some global data via fastify hook or globally, eg:\n\n```js\napp.locals.appName = \"My App\";\n\napp.addHook(\"onRequest\", (request, reply, done) =\u003e {\n  reply.locals.locale = \"en-US\";\n  reply.locals.serializedGlobals.locale = true;\n  done();\n});\n```\n\nThen later in a template access via:\n\n```marko\n\u003cdiv\u003e${out.global.appName}: ${out.global.locale}\u003c/div\u003e\n```\n\n## Using with `fastify-compress`\n\n[`fastify-compress`](https://github.com/fastify/fastify-compress) does not currently expose a way for Marko to indicate when it is appropriate to flush out content while streaming. The default behavior for [`zlib`](https://nodejs.org/api/zlib.html#flushing) is to buffer all content, which we don't wan't if we're trying to send out responses as fast as possible.\n\nTo properly use Marko with [`fastify-compress`](https://github.com/fastify/fastify-compress) you should configure it to allow flushing out content as it is written. Marko internally will be sure to only write to the response stream when we've reached a point where we're waiting for async content.\n\n```js\nimport zlib from \"zlib\";\nimport fastifyCompress from \"fastify-compress\";\n\nfastify.register(fastifyCompress, {\n  zlibOptions: {\n    flush: zlib.constants.Z_SYNC_FLUSH,\n  },\n  brotliOptions: {\n    flush: zlib.constants.BROTLI_OPERATION_FLUSH,\n  },\n});\n```\n\n# Code of Conduct\n\nThis project adheres to the [eBay Code of Conduct](./.github/CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarko-js%2Ffastify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarko-js%2Ffastify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarko-js%2Ffastify/lists"}