{"_id":"@btakita/sirv","_rev":"1-93f7b62ec305126c5caecace769e9a7e","name":"@btakita/sirv","dist-tags":{"latest":"0.4.2"},"versions":{"0.4.2":{"name":"@btakita/sirv","version":"0.4.2","description":"The optimized & lightweight middleware for serving requests to static assets","repository":{"type":"git","url":"git+https://github.com/lukeed/sirv.git"},"license":"MIT","author":{"name":"Luke Edwards","email":"luke@lukeed.com","url":"https://lukeed.com"},"engines":{"node":">= 6"},"publishConfig":{"access":"public"},"dependencies":{"@polka/url":"^0.5.0","mime":"^2.3.1"},"bugs":{"url":"https://github.com/lukeed/sirv/issues"},"homepage":"https://github.com/lukeed/sirv#readme","_id":"@btakita/sirv@0.4.2","_nodeVersion":"12.5.0","_npmVersion":"6.11.2","dist":{"integrity":"sha512-flv0zLkcDxNNVpn7f9cVIP4Gm4+W/68cgAQb7/cakVMDAfB11pUM10DgT9K4dltk1TnDPCTD5Y7jvnn0O0uJOw==","shasum":"95692db676d3adf0d86be3a67355cd9ca4935c83","tarball":"https://registry.npmjs.org/@btakita/sirv/-/sirv-0.4.2.tgz","fileCount":3,"unpackedSize":8946,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdaUmZCRA9TVsSAnZWagAApsEQAIMtmMpVX8wEiBU2rkzQ\nfJgQ06mmJBIkhxURqTkmFfqXDOeGdHFfp0182K+BPOym22L6g5gH+7onbFzH\n8otzkHkClqJsAdffKV/Siul50CWSYH4K+Xmiy7lXi9f7BFc1rVDgkwTwo0OE\njD6jUmQGnGeKsEcp1qMwbUf2cs3kn+DMRKzc+wc48UKRQ6bmokhuyO5BllQ8\nr//r/WRU1PvUz1WIYRD91W4i46DzolXLBfehlAtghoi1GMuy7KLwaZf6bjhI\nDjqi+oxDPs0fW1LaQOL8qSxpoS3N565Gh7DpKZ9toF4xWb1OY7BHg0wQWoY8\nUOtE1w0D/jUJvY+K1AdhxONYeJLZP3/TWAvpJhy2LrvIWZmFH6EQqqJiSIU7\n3xPfwmHIj2Ur9+bL6qxecPljSWLhJ+oCaPMJk/SH9XlCGf8WpZ2jeHhysEhd\nr3WLW4PVXzGMrXFTLVURRTO9RyuLkcdnlHfWBfn+kAYjm4pneeiitD/lfJB4\n+/IOu5YGa/lHPLYR3UeaGB8DCPKIaK1KnPwX3fnsizbPx+/fgYMCuPIHn/jK\nWAbv3mgPMjLdRgvhJ1kcNvS7DwirG/U2Nb7xiAPyEbDNDpD/+T4IBO8xVqpQ\ne7Rs5ceww1LeVKxrZDJ7UJu3rpXQqeQTaOt5TdHgplnMsg72FvMODVgL1J8W\nzOVz\r\n=u4Wh\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBNZr5mqZoWeW0IgWAHSR+heRHU+vzLjs3kW2Rnu9lF5AiAt6c8QjY/G55tksgY095qINHkKdpW6MxBg+2fxfTgVow=="}]},"maintainers":[{"name":"btakita","email":"brian.takita@gmail.com"}],"_npmUser":{"name":"btakita","email":"brian.takita@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sirv_0.4.2_1567181208888_0.1797708098223454"},"_hasShrinkwrap":false}},"time":{"created":"2019-08-30T16:06:48.668Z","0.4.2":"2019-08-30T16:06:49.026Z","modified":"2022-04-04T20:52:17.820Z"},"maintainers":[{"name":"btakita","email":"brian.takita@gmail.com"}],"description":"The optimized & lightweight middleware for serving requests to static assets","homepage":"https://github.com/lukeed/sirv#readme","repository":{"type":"git","url":"git+https://github.com/lukeed/sirv.git"},"author":{"name":"Luke Edwards","email":"luke@lukeed.com","url":"https://lukeed.com"},"bugs":{"url":"https://github.com/lukeed/sirv/issues"},"license":"MIT","readme":"# sirv [![Build Status](https://travis-ci.org/lukeed/sirv.svg?branch=master)](https://travis-ci.org/lukeed/sirv)\n\n> The optimized and lightweight middleware for serving requests to static assets\n\nYou may use `sirv` as a *very* fast and lightweight alternative to [`serve-static`](https://www.npmjs.com/package/serve-static). While (currently), `sirv` may not have the same options, it handles the majority of use cases without a hitch!\n\nThe massive performance advantage over `serve-static` is explained by **not** relying on the file system for existence checks on every request. These are expensive interactions & must be avoided whenever possible! Instead, `sirv` performs all its work upfront and recycles the initial resultset for existence checks & writing header values based on files' stats.\n\nThis middleware will work out of the box for [Polka](https://github.com/lukeed/polka) and other Express-like frameworks. It requires _very_ little effort to modify/wrap it for servers that don't accept the `(req, res, next)` signature.\n\n:bulb: For a feature-complete CLI application, check out the sibling [`sirv-cli`](https://github.com/lukeed/sirv/tree/master/packages/sirv-cli) package as an alternative to [`zeit/serve`](https://github.com/zeit/serve)~!\n\n## Install\n\n```\n$ npm install --save sirv\n```\n\n\n## Usage\n\n```js\nconst sirv = require('sirv');\nconst polka = require('polka');\nconst compress = require('compression')();\n\n// Init `sirv` handler\nconst assets = sirv('public', {\n  maxAge: 31536000, // 1Y\n  immutable: true\n});\n\npolka()\n  .use(compress, assets)\n  .use('/api', require('./api'))\n  .listen(3000)\n  .then(() => {\n    console.log('> Ready on localhost:3000~!');\n  });\n```\n\n\n## API\n\n### sirv(dir, opts={})\n\nReturns: `Function`\n\nThe returned function is a middleware in the standard Express-like signature: `(req, res, next)`, where `req` is the [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_incomingmessage), `res` is the [`http.ServerResponse`](https://nodejs.org/dist/latest-v9.x/docs/api/http.html#http_class_http_serverresponse), and `next` (in this case) is the function to call if no file was found for the given path.\n\nFor `sirv`, the `next()` callback is functionally synonymous with [`opts.onNoMatch`](#optsonnomatch); however `next()` is given priority if/when defined and **will not** receive the `res` as an argument.\n\n#### dir\nType: `String`<br>\nDefault: `.`\n\nThe directory from which to read and serve assets. It is resolved to an absolute path &mdash; you must provide an absolute path yourself if `process.cwd()` is not the correct assumption.\n\n#### opts.dev\nType: `Boolean`<br>\nDefault: `false`\n\nEnable \"dev\" mode, which disables/skips caching. Instead, `sirv` will traverse the file system ***on every request***.\n\nAdditionally, `dev` mode will ignore `maxAge`, `immutable`, `etag`, and `setHeaders` as these options are geared towards production response headers.\n\n> **Important:** Do not use `dev` mode in production!\n\n#### opts.etag\nType: `Boolean`<br>\nDefault: `false`\n\nGenerate and attach an `ETag` header to responses.\n\n#### opts.dotfiles\nType: `Boolean`<br>\nDefault: `false`\n\nAllow requests to dotfiles (files or directories beginning with a `.`).\n\n#### opts.extensions\nType: `Array`<br>\nDefault: `['html', 'htm']`\n\nThe file extension fallbacks to check for if a pathame is not initially found. For example, if a `/login` request cannot find a `login` filename, it will then look for `login.html` and `login.htm` before giving up~!\n\n> **Important:** Actually, `sirv` will **also** look for `login/index.html` and `login/index.htm` before calling it quits.\n\n#### opts.maxAge\nType: `Number`<br>\nDefault: `undefined`\n\nEnables the `Cache-Control` header on responses & sets the `max-age` value (in seconds). For example `31536000` is equivalent to one year.\n\n#### opts.immutable\nType: `Boolean`<br>\nDefault: `false`\n\nAppends the [`immutable` directive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Revalidation_and_reloading) on your `Cache-Control` header, used for uniquely-named assets that will not change!\n\n> **Note:** Requires `opts.maxAge` to contain a value!\n\n#### opts.onNoMatch\nType: `Function`\n\nA custom function to run if a file cannot be found for a given request. <br>By default, `sirv` will send a basic `(404) Not found` response.\n\nThe function receives the current `req <IncomingMessage>, res <ServerResponse>` pair for as its two arguments.\n\n> **Note:** This won't run if a `next` callback has been provided to the middleware; see [`sirv`](#sirvdir-opts) description.\n\n#### opts.setHeaders\nType: `Function`\n\nA custom function to append or change any headers on the outgoing response. There is no default.\n\nIts signature is `(res, pathname, stats)`, where `res` is the `ServerResponse`, `pathname` is incoming request path (stripped of queries), and `stats` is the file's result from [`fs.statSync`](https://nodejs.org/api/fs.html#fs_fs_statsync_path).\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","readmeFilename":"readme.md"}