{"id":15835052,"url":"https://github.com/kaelzhang/egg-serve-static","last_synced_at":"2025-10-11T03:43:00.152Z","repository":{"id":57220731,"uuid":"177255444","full_name":"kaelzhang/egg-serve-static","owner":"kaelzhang","description":"Utilities to create roe/egg route definitions to serve static files.","archived":false,"fork":false,"pushed_at":"2019-07-01T10:32:33.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T13:16:15.724Z","etag":null,"topics":["egg","roe"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaelzhang.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","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-03-23T06:56:12.000Z","updated_at":"2019-07-01T10:32:35.000Z","dependencies_parsed_at":"2022-08-29T04:01:27.050Z","dependency_job_id":null,"html_url":"https://github.com/kaelzhang/egg-serve-static","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fegg-serve-static","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fegg-serve-static/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fegg-serve-static/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fegg-serve-static/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaelzhang","download_url":"https://codeload.github.com/kaelzhang/egg-serve-static/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246638943,"owners_count":20809901,"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":["egg","roe"],"created_at":"2024-10-05T14:20:21.305Z","updated_at":"2025-10-11T03:43:00.074Z","avatar_url":"https://github.com/kaelzhang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/kaelzhang/egg-serve-static.svg?branch=master)](https://travis-ci.org/kaelzhang/egg-serve-static)\n[![Coverage](https://codecov.io/gh/kaelzhang/egg-serve-static/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/egg-serve-static)\n\u003c!-- optional appveyor tst\n[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/egg-serve-static?branch=master\u0026svg=true)](https://ci.appveyor.com/project/kaelzhang/egg-serve-static)\n--\u003e\n\u003c!-- optional npm version\n[![NPM version](https://badge.fury.io/js/egg-serve-static.svg)](http://badge.fury.io/js/egg-serve-static)\n--\u003e\n\u003c!-- optional npm downloads\n[![npm module downloads per month](http://img.shields.io/npm/dm/egg-serve-static.svg)](https://www.npmjs.org/package/egg-serve-static)\n--\u003e\n\u003c!-- optional dependency status\n[![Dependency Status](https://david-dm.org/kaelzhang/egg-serve-static.svg)](https://david-dm.org/kaelzhang/egg-serve-static)\n--\u003e\n\n# egg-serve-static\n\nUtilities to create [roe](https://github.com/kaelzhang/roe)/[egg](https://npmjs.org/package/egg) route definitions to serve static files.\n\n## Install\n\n```sh\n$ npm i egg-serve-static\n```\n\n## Usage\n\n```\nproject\n|-- app\n|   |-- router.js\n|-- static\n|   |-- a.js\n|-- compressed\n|   |-- a.min.js\n```\n\napp/router.js\n\n```js\nconst define = require('egg-serve-static')\n\nmodule.exports = define({\n  '/js': 'static',\n  '/min': {\n    root: 'compressed',\n    // Override the default max-age\n    maxAge: 60000\n  }\n}, {\n  root: '/path/to/project',\n  // Default max-age in miniseconds\n  maxAge: 120000\n})\n```\n\n## define(files, options)\n\n- **files** `Object` static files to serve\n- **options** `Object` configurations\n  - **root** `path` root path to search the files\n  - **maxAge?** `number=0` Browser cache max-age in milliseconds\n\nReturns `Function(app)` a roe/egg router function which accepts `app` as the only one parameter.\n\n### define.serve(app, path, root, options)\n\n- **app** `RoeApplication | EggApplication`\n- **path** `string` pathname of the request\n- **root** `path`\n- **options** `Object` the same as above\n\nAdd the router definition to `app`, then:\n\n```sh\ncurl http://localhost:$port$path/a.js\n\n# The content of file `${root}/a.js` will be sent\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Fegg-serve-static","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaelzhang%2Fegg-serve-static","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Fegg-serve-static/lists"}