{"id":14989565,"url":"https://github.com/choysen/koa-historify","last_synced_at":"2025-04-12T01:40:34.862Z","repository":{"id":37049362,"uuid":"300173387","full_name":"CHOYSEN/koa-historify","owner":"CHOYSEN","description":"💫 HTML5 History-API middleware for Koa2","archived":false,"fork":false,"pushed_at":"2024-03-15T06:59:27.000Z","size":487,"stargazers_count":5,"open_issues_count":11,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-15T07:52:45.428Z","etag":null,"topics":["html5-history","html5-history-middleware","koa","koa-historify","koa-middleware","koa2"],"latest_commit_sha":null,"homepage":"","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/CHOYSEN.png","metadata":{"files":{"readme":"README-zh_CN.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":"2020-10-01T06:36:51.000Z","updated_at":"2024-07-06T01:02:52.624Z","dependencies_parsed_at":"2022-07-12T16:13:30.129Z","dependency_job_id":"4b952ba6-f8fa-407a-9268-42cfe265e980","html_url":"https://github.com/CHOYSEN/koa-historify","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CHOYSEN%2Fkoa-historify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CHOYSEN%2Fkoa-historify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CHOYSEN%2Fkoa-historify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CHOYSEN%2Fkoa-historify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CHOYSEN","download_url":"https://codeload.github.com/CHOYSEN/koa-historify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248505714,"owners_count":21115352,"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":["html5-history","html5-history-middleware","koa","koa-historify","koa-middleware","koa2"],"created_at":"2024-09-24T14:18:34.815Z","updated_at":"2025-04-12T01:40:34.839Z","avatar_url":"https://github.com/CHOYSEN.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [koa-historify](https://github.com/CHOYSEN/koa-historify) 💫\n\n[![NPM version][npm-img]][npm-url]\n[![License][license-image]][license-url]\n\n正确设置 HTML5 History-API 的 Koa2 中间件\n\n[English](https://github.com/CHOYSEN/koa-historify/blob/master/README.md) | 中文\n\n## 为什么\n\n有别于目前依赖 `koa-static` fallback 的解决方案，本项目使用“默认路由”的思想来将未处理的 GET 请求重定向到 `index.html` 上。这种解决方案带来了更少的配置项和更直观的使用方式。\n\n## 安装\n\n```\nnpm install koa-historify --save\n```\n\n或者\n\n```\nyarn add koa-historify\n```\n\n## 使用\n\n```js\n// ...\nconst koaHistorify = require('koa-historify')\nconst indexPath = path.join(\n  __dirname,\n  'static/index.html' /* index.html 路径 */\n)\n\nconst app = new Koa()\n// ...\n// 确保在其它中间件之后使用，否则请使用 `prepose` 模式\napp.use(koaHistorify(indexPath))\napp.listen(80)\n```\n\n## 配置选项\n\n### logger\n\n你可以传入一个函数来记录日志\n\n```js\napp.use(\n  koaHistorify(indexPath, {\n    logger: console.log.bind(console)\n  })\n)\n```\n\n### prepose\n\n在 prepose 模式下，你可以在其他中间件被使用前使用它\n\n```js\n// ...\nconst staticPath = path.join(__dirname, 'static')\nconst indexPath = path.join(staticPath, 'index.html' /* index.html 路径 */)\n\nconst app = new Koa()\napp.use(\n  koaHistorify(indexPath, {\n    prepose: true\n  })\n)\napp.use(koaStatic(staticPath))\napp.use(router.routes())\n// ...\napp.listen(80)\n```\n\n## 开源许可\n\n[MIT](https://github.com/CHOYSEN/koa-historify/blob/master/LICENSE)\n\n[npm-img]: https://img.shields.io/npm/v/koa-historify?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-historify\n[license-image]: http://img.shields.io/npm/l/koa-historify?style=flat-square\n[license-url]: LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchoysen%2Fkoa-historify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchoysen%2Fkoa-historify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchoysen%2Fkoa-historify/lists"}