{"id":15046555,"url":"https://github.com/owengombas/static-koa-router","last_synced_at":"2026-01-19T10:33:36.463Z","repository":{"id":34243953,"uuid":"173097505","full_name":"owengombas/static-koa-router","owner":"owengombas","description":"Serve static files through koa-router","archived":false,"fork":false,"pushed_at":"2023-01-03T17:00:41.000Z","size":542,"stargazers_count":1,"open_issues_count":15,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T04:40:24.701Z","etag":null,"topics":["css","file","html","image","koa","public","router","serve","static"],"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/owengombas.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}},"created_at":"2019-02-28T11:11:18.000Z","updated_at":"2020-01-23T13:17:07.000Z","dependencies_parsed_at":"2023-01-15T05:36:18.300Z","dependency_job_id":null,"html_url":"https://github.com/owengombas/static-koa-router","commit_stats":null,"previous_names":["owencalvin/static-koa-router"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owengombas%2Fstatic-koa-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owengombas%2Fstatic-koa-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owengombas%2Fstatic-koa-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owengombas%2Fstatic-koa-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/owengombas","download_url":"https://codeload.github.com/owengombas/static-koa-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226196,"owners_count":20904465,"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":["css","file","html","image","koa","public","router","serve","static"],"created_at":"2024-09-24T20:53:13.871Z","updated_at":"2026-01-19T10:33:36.447Z","avatar_url":"https://github.com/owengombas.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Serve static file through koa-router\n[![Build Status](https://travis-ci.org/OwenCalvin/static-koa-router.svg?branch=master)](https://travis-ci.org/OwenCalvin/static-koa-router)\n\n## Installation\n```\nnpm i static-koa-router\n```\n```\nyarn add static-koa-router\n```\n\n### Usage\n`Serve(dirPath: string, router: Router, options?: Options)`\nYou simply need to pass the **dir path** at the first parameter, the **router instance** (koa-router) at the second parameter and optionaly the **options** at third parameter.\n\n##### Options\n - `maxage` Browser cache max-age in milliseconds. defaults to 0\n - `hidden` Allow transfer of hidden files. defaults to false\n - `index` Default file name, defaults to 'index.html'\n - `defer` If true, serves after `return next()`, allowing any downstream middleware to respond first.\n - `gzip`  Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. defaults to true.\n - `br`  Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists (note, that brotli is only accepted over https). defaults to true.\n - `extensions` Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults to `false`)\n - [setHeaders](https://github.com/koajs/send#setheaders) Function to set custom headers on response.\n\n### Examples\n\n##### Typescript\n```javascript\nimport { Serve } from \"static-koa-router\";\nimport * as KoaRouter from \"koa-router\";\nimport * as Koa from \"koa\";\nimport * as Http from \"http\";\n\nconst app = new Koa();\n\nconst router = new KoaRouter({\n  prefix: \"/public\"\n});\n\nServe(`${__dirname}/public`, router);\n\napp.use(router.routes());\n\nconst server = Http.createServer(app.callback());\n\nserver.listen(1337, \"localhost\", () =\u003e {\n  console.log(\"Server started\");\n});\n```\n\n##### Javascript\n```javascript\nconst { Serve } = require(\"static-koa-router\");\nconst KoaRouter = require(\"koa-router\");\nconst Koa = require(\"koa\");\nconst Http = require(\"http\");\n\nconst app = new Koa();\n\nconst router = new KoaRouter({\n  prefix: \"/public\"\n});\n\nServe(`${__dirname}/public`, router);\n\napp.use(router.routes());\n\nconst server = Http.createServer(app.callback());\n\nserver.listen(1337, \"localhost\", () =\u003e {\n  console.log(\"Server started\");\n});\n```\n\n### See also\n[koa-static](https://github.com/koajs/static)  \n[koa-send](https://github.com/koajs/send)  \n[koa-router](https://github.com/ZijianHe/koa-router)\n\n### License\nMIT - Owen Calvin\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowengombas%2Fstatic-koa-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fowengombas%2Fstatic-koa-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowengombas%2Fstatic-koa-router/lists"}