{"id":15434278,"url":"https://github.com/cenfun/koa-static-resolver","last_synced_at":"2025-04-19T18:09:04.142Z","repository":{"id":137916954,"uuid":"200989864","full_name":"cenfun/koa-static-resolver","owner":"cenfun","description":"Koa static file resolver, dirs, default index, path replace, cache, livereload, gzip","archived":false,"fork":false,"pushed_at":"2024-03-18T08:56:12.000Z","size":28,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T14:01:44.618Z","etag":null,"topics":["koa","static"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/cenfun.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2019-08-07T06:46:56.000Z","updated_at":"2024-11-26T03:59:13.000Z","dependencies_parsed_at":"2023-11-28T03:27:20.520Z","dependency_job_id":"174c8ee6-38e4-486c-af17-0499b6c8c8df","html_url":"https://github.com/cenfun/koa-static-resolver","commit_stats":{"total_commits":23,"total_committers":2,"mean_commits":11.5,"dds":0.04347826086956519,"last_synced_commit":"f454c98c3ac0e45ed66eb66b8f4170ab7f0e14cf"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cenfun%2Fkoa-static-resolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cenfun%2Fkoa-static-resolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cenfun%2Fkoa-static-resolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cenfun%2Fkoa-static-resolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cenfun","download_url":"https://codeload.github.com/cenfun/koa-static-resolver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248852182,"owners_count":21171842,"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":["koa","static"],"created_at":"2024-10-01T18:38:37.901Z","updated_at":"2025-04-19T18:09:04.123Z","avatar_url":"https://github.com/cenfun.png","language":"JavaScript","readme":"\n# Koa Static Resolver\n\u003e Koa static file resolver, dirs, default index, path replace, cache, livereload, gzip\n\n[![](https://img.shields.io/npm/v/koa-static-resolver)](https://www.npmjs.com/package/koa-static-resolver)\n[![](https://badgen.net/npm/dw/koa-static-resolver)](https://www.npmjs.com/package/koa-static-resolver)\n![](https://img.shields.io/github/license/cenfun/koa-static-resolver)\n\n## Install \n```sh\nnpm install koa-static-resolver --save\n```\n\n## Usage\n```js\nconst Koa = require('koa');\nconst KSR = require('koa-static-resolver');\nconst app = new Koa();\napp.use(KSR({\n    dirs: [\"./static/\", \"../node_modules/\"],\n    defaultIndex: \"index.html\"\n}));\napp.listen(8080);\n```\n\n## cache\n```js\napp.use(KSR({\n    dirs: [\"./static/\"],\n    //server cache (Memory)\n    cache: {},\n    //do NOT cache big size file\n    cacheMaxLength: 10 * 1024 * 1024,\n    //browser cache header: max-age=\u003cseconds\u003e\n    maxAge: 600\n}));\n```\n\n## livereload\n```js\napp.use(KSR({\n    dirs: [\"./static/\"],\n    livereload: '\\n\u003cscript src=\"/livereload.js\"\u003e\u003c/script\u003e\\n'\n}));\n//only inject to .html\n```\n\n## gzip\n```js\napp.use(KSR({\n    dirs: [\"./static/\"],\n    cache: {},\n    gzip: true,\n    gzipMinLength: 1024,\n    gzipTypes: [\".html\", \".css\", \".js\", \".svg\", \".xml\"]\n}));\n//require headers with \"Accept-Encoding\": \"gzip\"\n```\n\n## include/exclude\n```js\napp.use(KSR({\n    dirs: [\"./static/\"],\n    include: [\"include/folder\", /RegExp/],\n    exclude: [\"exclude/folder\", /RegExp/]\n}));\n// any files not matched include/folder will be 404 not found\n// any files matched exclude/folder will be 404 not found\n// support RegExp\n```\n\n## replace\n```js\napp.use(KSR({\n    dirs: [\"./static/\"],\n    replace: {\n      \"from_path\": \"to_path\"\n    }\n}));\n//when request /from_path/some_next_path/, will be replaced with /to_path/some_next_path/ to find out file path\n```\n\n## headers\n```js\napp.use(KSR({\n    dirs: [\"./static/\"],\n    headers: {\n      \"header_key\": \"header_value\"\n    }\n}));\n```\n\n\n## CHANGELOG\n\n+ v1.0.5\n  - added test case\n  - added types\n\n+ v1.0.4\n  - added include/exclude match for file path\n\n+ v1.0.3\n  - fixed cache issue if maxAge=0\n\n+ v1.0.2\n  - fixed livereload\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcenfun%2Fkoa-static-resolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcenfun%2Fkoa-static-resolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcenfun%2Fkoa-static-resolver/lists"}