{"_id":"@docusaurus/serve-handler","name":"@docusaurus/serve-handler","dist-tags":{"latest":"6.2.0"},"versions":{"6.2.0":{"name":"@docusaurus/serve-handler","version":"6.2.0","description":"The routing foundation of `serve` and static deployments on Now","publishConfig":{"access":"public"},"main":"src/index.js","scripts":{"test":"yarn run test-lint && yarn run test-integration","test-lint":"zeit-eslint --ext .jsx,.js .","test-integration":"nyc --reporter=html --reporter=text ava test/integration.js","coverage":"nyc report --reporter=text-lcov > coverage.lcov","lint-staged":"git diff --diff-filter=ACMRT --cached --name-only '*.js' '*.jsx' | xargs zeit-eslint","build-views":"dottojs -s ./src -d ./src","prepublishOnly":"yarn run build-views"},"repository":{"type":"git","url":"https://github.com/zeit/serve-handler.git"},"keywords":["static","deployment","server"],"author":{"name":"leo"},"license":"MIT","devDependencies":{"@zeit/eslint-config-node":"0.2.13","@zeit/git-hooks":"0.1.4","ava":"2.2.0","commander":"2.15.1","dot":"1.1.3","eslint":"6.1.0","fs-extra":"6.0.1","micro":"9.3.2","node-fetch":"2.6.1","nyc":"14.1.1","request":"2.87.0","sleep-promise":"6.0.0","test-listen":"1.1.0"},"eslintConfig":{"extends":["@zeit/eslint-config-node"]},"nyc":{"exclude":["src/directory.js","src/error.js","test/*"]},"eslintIgnore":["error.js","directory.js","coverage"],"git":{"pre-commit":"lint-staged"},"dependencies":{"bytes":"3.0.0","content-disposition":"0.5.2","mime-types":"2.1.18","minimatch":"3.1.2","path-is-inside":"1.0.2","path-to-regexp":"2.2.1","range-parser":"1.2.0"},"licenseText":"MIT License\n\nCopyright (c) 2018 ZEIT, Inc.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@docusaurus/serve-handler@6.2.0","dist":{"shasum":"64d3e58ff5e5eaf7caf97e20e6695fd2510b9e6d","integrity":"sha512-bTu+jOVeSHjUjaaK1JYqzBCWRHVEOYoMtHrO+uhLYG71NxtwrtpnLsYVr4uSlEyGIqjhW1Ie49sGAfDoGUJa0A==","tarball":"https://registry.npmjs.org/@docusaurus/serve-handler/-/serve-handler-6.2.0.tgz","fileCount":9,"unpackedSize":42845,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICzeOYxFJ4256OHBNWOpnKcGx32WkXuTAsxKGplaXlFzAiEA7oadNZ3WJU/Oy5cl+JTmsUNdJsu6p/lomhIuUf5IKYg="}]},"_npmUser":{"name":"slorber","email":"lorber.sebastien@gmail.com"},"directories":{},"maintainers":[{"name":"fb","email":"opensource+npm@fb.com"},{"name":"slorber","email":"lorber.sebastien@gmail.com"},{"name":"lex111","email":"lex61rus@gmail.com"},{"name":"docusaurus-bot","email":"opensource+npm-docusaurus@fb.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/serve-handler_6.2.0_1724432069980_0.7901620863497418"},"_hasShrinkwrap":false}},"time":{"created":"2024-08-23T16:54:29.867Z","6.2.0":"2024-08-23T16:54:30.203Z","modified":"2024-08-23T16:54:30.550Z"},"maintainers":[{"name":"fb","email":"opensource+npm@fb.com"},{"name":"slorber","email":"lorber.sebastien@gmail.com"},{"name":"lex111","email":"lex61rus@gmail.com"},{"name":"docusaurus-bot","email":"opensource+npm-docusaurus@fb.com"}],"description":"The routing foundation of `serve` and static deployments on Now","keywords":["static","deployment","server"],"repository":{"type":"git","url":"https://github.com/zeit/serve-handler.git"},"author":{"name":"leo"},"license":"MIT","readme":"# serve-handler\n\n\n## Docusaurus Fork!\n\nThe whole purpose of this fork is to get rid of the Node 21 punycode warning. \n\nSee:\n- https://github.com/facebook/docusaurus/issues/10107\n- https://github.com/vercel/serve-handler/issues/204\n\nDocusaurus maintainers don't plan to maintain it further.\n\n---\n\n[![Tests](https://github.com/vercel/serve-handler/actions/workflows/tests.yaml/badge.svg)](https://github.com/vercel/serve-handler/actions/workflows/tests.yaml)\n[![codecov](https://codecov.io/gh/vercel/serve-handler/branch/main/graph/badge.svg)](https://codecov.io/gh/vercel/serve-handler)\n[![install size](https://packagephobia.now.sh/badge?p=serve-handler)](https://packagephobia.now.sh/result?p=serve-handler)\n\nThis package represents the core of [serve](https://github.com/vercel/serve). It can be plugged into any HTTP server and is responsible for routing requests and handling responses.\n\nIn order to customize the default behaviour, you can also pass custom routing rules, provide your own methods for interacting with the file system and much more.\n\n## Usage\n\nGet started by installing the package using [yarn](https://yarnpkg.com/lang/en/):\n\n```sh\nyarn add serve-handler\n```\n\nYou can also use [npm](https://www.npmjs.com/) instead, if you'd like:\n\n```sh\nnpm install serve-handler\n```\n\nNext, add it to your HTTP server. Here's an example using [micro](https://github.com/vercel/micro):\n\n```js\nconst handler = require('serve-handler');\n\nmodule.exports = async (request, response) => {\n  await handler(request, response);\n};\n```\n\nThat's it! :tada:\n\n## Options\n\nIf you want to customize the package's default behaviour, you can use the third argument of the function call to pass any of the configuration options listed below. Here's an example:\n\n```js\nawait handler(request, response, {\n  cleanUrls: true\n});\n```\n\nYou can use any of the following options:\n\n| Property                                             | Description                                                           |\n|------------------------------------------------------|-----------------------------------------------------------------------|\n| [`public`](#public-string)                           | Set a sub directory to be served                                      |\n| [`cleanUrls`](#cleanurls-booleanarray)               | Have the `.html` extension stripped from paths                        |\n| [`rewrites`](#rewrites-array)                        | Rewrite paths to different paths                                      |\n| [`redirects`](#redirects-array)                      | Forward paths to different paths or external URLs                     |\n| [`headers`](#headers-array)                          | Set custom headers for specific paths                                 |\n| [`directoryListing`](#directorylisting-booleanarray) | Disable directory listing or restrict it to certain paths             |\n| [`unlisted`](#unlisted-array)                        | Exclude paths from the directory listing                              |\n| [`trailingSlash`](#trailingslash-boolean)            | Remove or add trailing slashes to all paths                           |\n| [`renderSingle`](#rendersingle-boolean)              | If a directory only contains one file, render it                      |\n| [`symlinks`](#symlinks-boolean)                      | Resolve symlinks instead of rendering a 404 error                     |\n| [`etag`](#etag-boolean)                              | Calculate a strong `ETag` response header, instead of `Last-Modified` |\n\n### public (String)\n\nBy default, the current working directory will be served. If you only want to serve a specific path, you can use this options to pass an absolute path or a custom directory to be served relative to the current working directory.\n\nFor example, if serving a [Jekyll](https://jekyllrb.com/) app, it would look like this:\n\n```json\n{\n  \"public\": \"_site\"\n}\n```\n\nUsing absolute path:\n\n```json\n{\n  \"public\": \"/path/to/your/_site\"\n}\n```\n\n**NOTE:** The path cannot contain globs or regular expressions.\n\n### cleanUrls (Boolean|Array)\n\nBy default, all `.html` files can be accessed without their extension.\n\nIf one of these extensions is used at the end of a filename, it will automatically perform a redirect with status code [301](https://en.wikipedia.org/wiki/HTTP_301) to the same path, but with the extension dropped.\n\nYou can disable the feature like follows:\n\n```json\n{\n  \"cleanUrls\": false\n}\n```\n\nHowever, you can also restrict it to certain paths:\n\n```json\n{\n  \"cleanUrls\": [\n    \"/app/**\",\n    \"/!components/**\"\n  ]\n}\n```\n\n**NOTE:** The paths can only contain globs that are matched using [minimatch](https://github.com/isaacs/minimatch).\n\n### rewrites (Array)\n\nIf you want your visitors to receive a response under a certain path, but actually serve a completely different one behind the curtains, this option is what you need.\n\nIt's perfect for [single page applications](https://en.wikipedia.org/wiki/Single-page_application) (SPAs), for example:\n\n```json\n{\n  \"rewrites\": [\n    { \"source\": \"app/**\", \"destination\": \"/index.html\" },\n    { \"source\": \"projects/*/edit\", \"destination\": \"/edit-project.html\" }\n  ]\n}\n```\n\nYou can also use so-called \"routing segments\" as follows:\n\n```json\n{\n  \"rewrites\": [\n    { \"source\": \"/projects/:id/edit\", \"destination\": \"/edit-project-:id.html\" },\n  ]\n}\n```\n\nNow, if a visitor accesses `/projects/123/edit`, it will respond with the file `/edit-project-123.html`.\n\n**NOTE:** The paths can contain globs (matched using [minimatch](https://github.com/isaacs/minimatch)) or regular expressions (match using [path-to-regexp](https://github.com/pillarjs/path-to-regexp)).\n\n### redirects (Array)\n\nIn order to redirect visits to a certain path to a different one (or even an external URL), you can use this option:\n\n```json\n{\n  \"redirects\": [\n    { \"source\": \"/from\", \"destination\": \"/to\" },\n    { \"source\": \"/old-pages/**\", \"destination\": \"/home\" }\n  ]\n}\n```\n\nBy default, all of them are performed with the status code [301](https://en.wikipedia.org/wiki/HTTP_301), but this behavior can be adjusted by setting the `type` property directly on the object (see below).\n\nJust like with [rewrites](#rewrites-array), you can also use routing segments:\n\n```json\n{\n  \"redirects\": [\n    { \"source\": \"/old-docs/:id\", \"destination\": \"/new-docs/:id\" },\n    { \"source\": \"/old\", \"destination\": \"/new\", \"type\": 302 }\n  ]\n}\n```\n\nIn the example above, `/old-docs/12` would be forwarded to `/new-docs/12` with status code [301](https://en.wikipedia.org/wiki/HTTP_301). In addition `/old` would be forwarded to `/new` with status code [302](https://en.wikipedia.org/wiki/HTTP_302).\n\n**NOTE:** The paths can contain globs (matched using [minimatch](https://github.com/isaacs/minimatch)) or regular expressions (match using [path-to-regexp](https://github.com/pillarjs/path-to-regexp)).\n\n### headers (Array)\n\nAllows you to set custom headers (and overwrite the default ones) for certain paths:\n\n```json\n{\n  \"headers\": [\n    {\n      \"source\" : \"**/*.@(jpg|jpeg|gif|png)\",\n      \"headers\" : [{\n        \"key\" : \"Cache-Control\",\n        \"value\" : \"max-age=7200\"\n      }]\n    }, {\n      \"source\" : \"404.html\",\n      \"headers\" : [{\n        \"key\" : \"Cache-Control\",\n        \"value\" : \"max-age=300\"\n      }]\n    }\n  ]\n}\n```\n\nIf you define the `ETag` header for a path, the handler will automatically reply with status code `304` for that path if a request comes in with a matching `If-None-Match` header.\n\nIf you set a header `value` to `null` it removes any previous defined header with the same key.\n\n**NOTE:** The paths can only contain globs that are matched using [minimatch](https://github.com/isaacs/minimatch).\n\n### directoryListing (Boolean|Array)\n\nFor paths are not files, but directories, the package will automatically render a good-looking list of all the files and directories contained inside that directory.\n\nIf you'd like to disable this for all paths, set this option to `false`. Furthermore, you can also restrict it to certain directory paths if you want:\n\n```json\n{\n  \"directoryListing\": [\n    \"/assets/**\",\n    \"/!assets/private\"\n  ]\n}\n```\n\n**NOTE:** The paths can only contain globs that are matched using [minimatch](https://github.com/isaacs/minimatch).\n\n### unlisted (Array)\n\nIn certain cases, you might not want a file or directory to appear in the directory listing. In these situations, there are two ways of solving this problem.\n\nEither you disable the directory listing entirely (like shown [here](#directorylisting-booleanarray)), or you exclude certain paths from those listings by adding them all to this config property.\n\n```json\n{\n  \"unlisted\": [\n    \".DS_Store\",\n    \".git\"\n  ]\n}\n```\n\nThe items shown above are excluded from the directory listing by default.\n\n**NOTE:** The paths can only contain globs that are matched using [minimatch](https://github.com/isaacs/minimatch).\n\n### trailingSlash (Boolean)\n\nBy default, the package will try to make assumptions for when to add trailing slashes to your URLs or not. If you want to remove them, set this property to `false` and `true` if you want to force them on all URLs:\n\n```js\n{\n  \"trailingSlash\": true\n}\n```\n\nWith the above config, a request to `/test` would now result in a [301](https://en.wikipedia.org/wiki/HTTP_301) redirect to `/test/`.\n\n### renderSingle (Boolean)\n\nSometimes you might want to have a directory path actually render a file, if the directory only contains one. This is only useful for any files that are not `.html` files (for those, [`cleanUrls`](#cleanurls-booleanarray) is faster).\n\nThis is disabled by default and can be enabled like this:\n\n```js\n{\n  \"renderSingle\": true\n}\n```\n\nAfter that, if you access your directory `/test` (for example), you will see an image being rendered if the directory contains a single image file.\n\n### symlinks (Boolean)\n\nFor security purposes, symlinks are disabled by default. If `serve-handler` encounters a symlink, it will treat it as if it doesn't exist in the first place. In turn, a 404 error is rendered for that path.\n\nHowever, this behavior can easily be adjusted:\n\n```js\n{\n  \"symlinks\": true\n}\n```\n\nOnce this property is set as shown above, all symlinks will automatically be resolved to their targets.\n\n### etag (Boolean)\n\nHTTP response headers will contain a strong [`ETag`][etag] response header, instead of a [`Last-Modified`][last-modified] header. Opt-in because calculating the hash value may be computationally expensive for large files.\n\nSending an `ETag` header is disabled by default and can be enabled like this:\n\n```js\n{\n  \"etag\": true\n}\n```\n\n## Error templates\n\nThe handler will automatically determine the right error format if one occurs and then sends it to the client in that format.\n\nFurthermore, this allows you to not just specifiy an error template for `404` errors, but also for all other errors that can occur (e.g. `400` or `500`).\n\nJust add a `<status-code>.html` file to the root directory and you're good.\n\n## Middleware\n\nIf you want to replace the methods the package is using for interacting with the file system and sending responses, you can pass them as the fourth argument to the function call.\n\nThese are the methods used by the package (they can all return a `Promise` or be asynchronous):\n\n```js\nawait handler(request, response, undefined, {\n  lstat(path) {},\n  realpath(path) {},\n  createReadStream(path, config) {}\n  readdir(path) {},\n  sendError(absolutePath, response, acceptsJSON, root, handlers, config, error) {}\n});\n```\n\n**NOTE:** It's important that – for native methods like `createReadStream` – all arguments are passed on to the native call.\n\n## Author\n\nLeo Lamprecht ([@leo](https://x.com/leo)) - [Vercel](https://vercel.com)\n\n\n[etag]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag\n[last-modified]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified\n","readmeFilename":"README.md"}