{"id":51229212,"url":"https://github.com/mridang/nestjs-platform-cloudflare","last_synced_at":"2026-06-28T14:30:57.027Z","repository":{"id":364029459,"uuid":"1264787399","full_name":"mridang/nestjs-platform-cloudflare","owner":"mridang","description":"NestJS HTTP platform adapter for Cloudflare Workers — run Nest natively on the fetch API, no Express, no node:http, no port.","archived":false,"fork":false,"pushed_at":"2026-06-11T10:47:46.000Z","size":527,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-11T11:22:19.151Z","etag":null,"topics":["adapter","cloudflare","cloudflare-workers","fetch","http-adapter","nest","nestjs","serverless","typescript","workers"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@mridang/nestjs-platform-cloudflare","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mridang.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-10T07:19:00.000Z","updated_at":"2026-06-11T10:44:40.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mridang/nestjs-platform-cloudflare","commit_stats":null,"previous_names":["mridang/nestjs-platform-cloudflare"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/mridang/nestjs-platform-cloudflare","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mridang%2Fnestjs-platform-cloudflare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mridang%2Fnestjs-platform-cloudflare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mridang%2Fnestjs-platform-cloudflare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mridang%2Fnestjs-platform-cloudflare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mridang","download_url":"https://codeload.github.com/mridang/nestjs-platform-cloudflare/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mridang%2Fnestjs-platform-cloudflare/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34892546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["adapter","cloudflare","cloudflare-workers","fetch","http-adapter","nest","nestjs","serverless","typescript","workers"],"created_at":"2026-06-28T14:30:56.952Z","updated_at":"2026-06-28T14:30:57.018Z","avatar_url":"https://github.com/mridang.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NestJS Platform - Cloudflare\n\nA NestJS HTTP platform adapter that runs NestJS applications natively on\n[Cloudflare Workers](https://workers.cloudflare.com/), with no Express, no\n`node:http`, and no port.\n\nThis adapter implements the NestJS `AbstractHttpAdapter` directly over the\nWeb Fetch API. It routes an incoming `Request` straight into the Nest\nrequest pipeline and returns a `Response`, so your controllers, providers,\nguards, pipes, and interceptors run unchanged. Express and Fastify\nmiddleware are supported through dedicated compatibility layers, so you can\nkeep using packages like `helmet` and `cookie-parser` without pulling in a\nfull Node.js HTTP framework.\n\n## Why?\n\nRunning NestJS on Cloudflare Workers usually means wrapping the framework in\nan emulated Node.js HTTP server (`node:http`) and an Express instance, then\nbridging the Worker's `fetch` event into that stack. That works, but it\nships a large emulation layer to every isolate and pays for it on every cold\nstart.\n\nWorkers do not have a long-running server or a port; their entry point is a\nsingle `fetch(request)` handler. This adapter embraces that model instead of\nhiding it. The Nest core is platform-agnostic — only the HTTP edge is\nCloudflare-specific — so the adapter is the one place that knows about\nWorkers, and your application code imports nothing but `@nestjs/*`.\n\nThe result is a smaller bundle, a faster cold start, and no Express or\n`node:http` shim in the request path, while keeping the parts of the Express\nand Fastify ecosystems that are genuinely useful through opt-in\ncompatibility layers.\n\n## Installation\n\nInstall using NPM with the following command:\n\n```sh\nnpm install --save @mridang/nestjs-platform-cloudflare\n```\n\nThis package declares `@nestjs/common` and `@nestjs/core` as peer\ndependencies, so make sure they are installed in your project.\n\n## Usage\n\nCreate the application with the `CloudflareAdapter`, initialise it once, and\nexport a `fetch` handler that hands each request to the adapter. There is no\n`app.listen()` — Workers invoke the `fetch` export directly.\n\n```typescript\nimport 'reflect-metadata';\nimport { NestFactory } from '@nestjs/core';\nimport { CloudflareAdapter } from '@mridang/nestjs-platform-cloudflare';\nimport { AppModule } from './app.module.js';\n\nconst adapter = new CloudflareAdapter();\nconst app = await NestFactory.create(AppModule, adapter, { logger: false });\nawait app.init();\n\nexport default {\n  fetch: (request: Request): Promise\u003cResponse\u003e =\u003e adapter.handle(request),\n};\n```\n\nYour controllers are ordinary NestJS controllers and need no changes:\n\n```typescript\nimport { Controller, Get, Post, Body, Param } from '@nestjs/common';\n\n@Controller('widgets')\nexport class WidgetsController {\n  @Get(':id')\n  findOne(@Param('id') id: string) {\n    return { id };\n  }\n\n  @Post()\n  create(@Body() body: unknown) {\n    return { created: body };\n  }\n}\n```\n\nThe request body is parsed natively (`application/json`,\n`application/x-www-form-urlencoded`, and `multipart/form-data`), the raw\nbytes are exposed as a `Buffer` on `request.rawBody` when the application is\ncreated with `{ rawBody: true }`, and the client IP is read from the\n`cf-connecting-ip` header for the `@Ip()` decorator.\n\n## Express Middleware\n\nReal Express middleware runs through a compatibility layer that builds an\nExpress-shaped request and response from the native `Request`. Register\nmiddleware globally or scoped to a path prefix:\n\n```typescript\nimport helmet from 'helmet';\nimport cookieParser from 'cookie-parser';\n\nconst adapter = new CloudflareAdapter();\nadapter.useExpressMiddleware(helmet());\nadapter.useExpressMiddleware(cookieParser());\nadapter.useExpressMiddleware('/api', compression());\n```\n\nMiddleware that only reads headers and sets response headers (security\nheaders, cookies, CORS) works unchanged. Middleware that consumes the\nrequest as a Node.js stream (for example `body-parser` or `multer`) is not\nsupported — use the adapter's native body parsing and `multipart/form-data`\nhandling instead.\n\n## Fastify Hooks\n\nFastify lifecycle hooks are supported through the Fastify compatibility\nlayer:\n\n```typescript\nadapter.useFastifyHook('onRequest', async (request, reply) =\u003e {\n  reply.header('x-powered-by', 'nestjs-platform-cloudflare');\n});\n```\n\n## CORS\n\nEnable CORS with the standard NestJS API; preflight `OPTIONS` requests are\nanswered automatically:\n\n```typescript\nconst app = await NestFactory.create(AppModule, adapter);\napp.enableCors({ origin: 'https://example.com', credentials: true });\n```\n\n## Known Issues\n\n- **Static assets:** `useStaticAssets()` is a no-op. Serve static files with\n  the Cloudflare Workers\n  [static assets](https://developers.cloudflare.com/workers/static-assets/)\n  binding instead of the filesystem.\n- **View engines:** server-side template rendering (`@Render()`) is not\n  supported. Return strings or `Response` objects from controllers instead.\n- **Streaming request bodies:** the request body is read once and buffered;\n  there is no incremental streaming into the controller.\n- **Server-Sent Events and open-ended `@Res()` handlers:** Server-Sent Events\n  (`@Sse()`) and handlers that take the raw response via `@Res()` but never\n  send a response are not supported. The adapter buffers the response and\n  awaits it settling before returning, so a handler that never sends will hang\n  rather than stream.\n\n## Useful links\n\n- **[Cloudflare Workers](https://developers.cloudflare.com/workers/):**\n  Workers platform documentation.\n- **[NestJS](https://docs.nestjs.com/):** NestJS framework documentation.\n- **[Custom adapters](https://docs.nestjs.com/faq/http-adapter):** NestJS\n  HTTP adapter documentation.\n\n## Contributing\n\nIf you have suggestions for how this adapter could be improved, or want to\nreport a bug, open an issue — we'd love all and any contributions.\n\n## License\n\nApache License 2.0 © 2024 Mridang Agarwalla\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmridang%2Fnestjs-platform-cloudflare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmridang%2Fnestjs-platform-cloudflare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmridang%2Fnestjs-platform-cloudflare/lists"}