{"id":15375969,"url":"https://github.com/thepassle/astro-router","last_synced_at":"2025-07-20T12:06:17.880Z","repository":{"id":98993831,"uuid":"481619045","full_name":"thepassle/astro-router","owner":"thepassle","description":null,"archived":false,"fork":false,"pushed_at":"2022-04-14T13:41:21.000Z","size":1,"stargazers_count":22,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T16:26:28.184Z","etag":null,"topics":["astro","router","srr"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/astro-router","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thepassle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-04-14T13:40:39.000Z","updated_at":"2024-03-21T16:01:03.000Z","dependencies_parsed_at":"2023-03-04T06:00:35.263Z","dependency_job_id":null,"html_url":"https://github.com/thepassle/astro-router","commit_stats":{"total_commits":1,"total_committers":1,"mean_commits":1.0,"dds":0.0,"last_synced_commit":"7d1695755619bb33841fbd20a19695bc54c638a0"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thepassle/astro-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thepassle%2Fastro-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thepassle%2Fastro-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thepassle%2Fastro-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thepassle%2Fastro-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thepassle","download_url":"https://codeload.github.com/thepassle/astro-router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thepassle%2Fastro-router/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266120452,"owners_count":23879322,"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":["astro","router","srr"],"created_at":"2024-10-01T14:05:25.400Z","updated_at":"2025-07-20T12:06:17.856Z","avatar_url":"https://github.com/thepassle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# astro-router\n\nAt the time of writing, Astro SSR does not yet support Middleware. This project is just a simple router that adds middleware to your Astro SSR projects, as well as some utilities like getting params, query params, headers, etc.\n\n## Installation\n\n```\nnpm i -S astro-router\n```\n\n## Usage\n\nImport the `router`:\n```js\nimport { router } from 'astro-router';\n```\n\nThen export your `get`, `post`, etc:\n`/foo/[...all]/index.js`:\n```js\nexport const get = router({\n  routes: [\n    {\n      path: '/foo',\n      response: () =\u003e new Response(null, {status: 200})\n    }\n  ]\n});\n```\n\n## Examples\n\n`/sales/[...all]/index.js`:\n```js\nimport { router } from 'astro-router';\nimport { auth, logger } from './middleware.js';\nimport { User, Order } from './db.js';\n\nexport const get = router({\n  routes: [\n    {\n      path: '/sales/:user/:order',\n      middleware: [logger, auth],\n      response({params}) {\n        const user = await User.findOne({id: params.user});\n        const order = await Order.findOne({id: params.order});\n\n        return new Response(null, {status: 200});\n      }\n    }\n  ]\n})\n```\n\n`Request: /users/1234?foo=bar`:\n```js\nexport const get = router({\n  path: '/users/:id',\n  middleware: [logger, auth],\n  response: ({params, query}) =\u003e {\n    console.log(params.id) // '1234'\n    console.log(query.foo) // 'bar'\n  }\n});\n```\n\n## Api\n\n### Router\n\n```js\nexport const get = router({\n  /** Routes */\n  routes: [\n    {\n      /** The path to match, supports 'express'-style route params */\n      path: '/users/:id',\n      middleware: [\n        ({\n          /** Astro's original `request` object */\n          request,\n          /** Any query params as object */\n          query,\n          /** Route params as object */\n          params,\n          /** Headers as object */\n          headers\n          /** Url object */\n          url,\n          /** Next middleware to invoke */\n          next\n        }) =\u003e {\n          next();\n        }\n      ],\n      response: ({\n        /** Astro's original `request` object */\n        request,\n        /** Any query params as object */\n        query,\n        /** Route params as object */\n        params,\n        /** Headers as object */\n        headers\n        /** Url object */\n        url,\n      }) =\u003e {\n        return new Response(null, {status: 200})\n      }\n    }\n  ],\n  /** \n   * Custom fallback in case no routes match \n   * defaults to a 404 response\n   */\n  fallback: () =\u003e new Response(null, {status: 404}),\n})\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthepassle%2Fastro-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthepassle%2Fastro-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthepassle%2Fastro-router/lists"}