{"id":15019372,"url":"https://github.com/dfischer/firebase-functions-router","last_synced_at":"2026-01-20T18:56:07.084Z","repository":{"id":57236604,"uuid":"132536918","full_name":"dfischer/firebase-functions-router","owner":"dfischer","description":"Router controller pattern to use with firebase functions.","archived":false,"fork":false,"pushed_at":"2018-05-08T04:45:36.000Z","size":11,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-14T14:03:57.095Z","etag":null,"topics":["firebase","firebase-functions","typescript"],"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/dfischer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-08T01:33:27.000Z","updated_at":"2020-01-02T18:27:02.000Z","dependencies_parsed_at":"2022-08-26T14:04:09.469Z","dependency_job_id":null,"html_url":"https://github.com/dfischer/firebase-functions-router","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfischer%2Ffirebase-functions-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfischer%2Ffirebase-functions-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfischer%2Ffirebase-functions-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfischer%2Ffirebase-functions-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dfischer","download_url":"https://codeload.github.com/dfischer/firebase-functions-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648911,"owners_count":20972944,"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":["firebase","firebase-functions","typescript"],"created_at":"2024-09-24T19:53:23.846Z","updated_at":"2026-01-20T18:56:07.047Z","avatar_url":"https://github.com/dfischer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/dfischer/firebase-functions-router.svg?branch=master)](https://travis-ci.org/dfischer/firebase-functions-router)\n\n# firebase-functions-router\n\nRouter controller pattern to use with firebase functions or anything else that needs a generic interface to express-like `req, res` expectations.\n\n## Usage\n\nFirebase https onRequest handler\n\n```typescript\nexport const HelloRouter = functions.https.onRequest(async (req, res) =\u003e {\n  try {\n    return await MyRouter(req, res);\n  } catch (e) {\n    console.error(e);\n    return res.sendStatus(500);\n  }\n});\n```\n\nand then you'd have a `HelloRouter` somewhere in your application like so:\n\n```typescript\nconst HelloRouter = async (req, res) =\u003e {\n  return await Router({\n    req,\n    res,\n    get: async (_, res) =\u003e {\n      return await res.sendStatus(200);\n    },\n  });\n};\n```\n\nAdd as many method handlers as you want per http spec.\n\n## Middleware\n\nIf you want to do something fancy between the request cycle and when the router instance responds, then you may want to use middleware.\n\nThe Router takes middleware options like so:\n\n```typescript\n// imagine async stuff\nconst AuthMiddleware = async router =\u003e {\n  return await {\n    req: {\n      ...router.req,\n      auth: await getUser('dan')\n    },\n    res: router.res,\n  };\n};\n\nconst FooMiddleware = async router =\u003e {\n  return await {\n    req: {\n      ...router.req,\n      foo: await getFoo(); // async func that returns 'bar'\n    },\n    res: router.res,\n  };\n};\n\nconst router = async (req, res) =\u003e {\n  return await Router({\n    req,\n    res,\n    middleware: [AuthMiddleware, FooMiddleware],\n    get: async (req, res) =\u003e {\n      if (req.auth === 'dan' \u0026\u0026 req.foo === 'bar')\n        return await res.sendStatus(200);\n    },\n  });\n};\n```\n\nMore examples are in the spec files.\n\n# Development\n\nWritten in TypeScript.\n\n# Contributing\n\nJust open a PR (with tests if it makes sense.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfischer%2Ffirebase-functions-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdfischer%2Ffirebase-functions-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfischer%2Ffirebase-functions-router/lists"}