{"_id":"@dsinni/connect-history-api-fallback","_rev":"2-766d7547e11fa1a42cc8663ed4d55ae0","name":"@dsinni/connect-history-api-fallback","dist-tags":{"latest":"1.6.0"},"versions":{"1.6.0":{"name":"@dsinni/connect-history-api-fallback","version":"1.6.0","description":"Provides a fallback for non-existing directories so that the HTML 5 history API can be used.","keyswords":["connect","html5","history api","fallback","spa"],"engines":{"node":">=0.8"},"main":"lib/index.js","scripts":{"test":"jest && eslint lib/*.js test/*.js"},"repository":{"type":"git","url":"git+ssh://git@github.com/dsinni/connect-history-api-fallback.git"},"author":{"name":"Ben Ripkens","email":"bripkens@gmail.com"},"contributors":[{"name":"Craig Myles","email":"cr@igmyles.com","url":"http://www.craigmyles.com"}],"license":"MIT","devDependencies":{"eslint":"^5.16.0","jest":"^24.8.0","sinon":"^7.3.2"},"gitHead":"ab637ac14bb6c96766543dae9ba6ec59a7a31a4b","bugs":{"url":"https://github.com/dsinni/connect-history-api-fallback/issues"},"homepage":"https://github.com/dsinni/connect-history-api-fallback#readme","_id":"@dsinni/connect-history-api-fallback@1.6.0","_nodeVersion":"14.16.1","_npmVersion":"6.14.12","dist":{"integrity":"sha512-w4IOfhpIBOPJsn3kubTGS1F6IN7L6Zyuxnst/taCCcgRd+hIb0saBWT2YXZtNmFVJsrwDSrEkfn5xuC+BGgESg==","shasum":"529cf087af131ac1d5515b946dab1c3523545be6","tarball":"https://registry.npmjs.org/@dsinni/connect-history-api-fallback/-/connect-history-api-fallback-1.6.0.tgz","fileCount":5,"unpackedSize":12242,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhzz31CRA9TVsSAnZWagAA0f8P/2giJ5YKxcg9iXXg6WGd\nH9NAnvy6bpXxivQ7tnT2RIEglN5kr314gJeGQ5xXTkcvyiCVs9HM8/jtqk1w\nqiRthqOKZwtcQhJPk6uhaTsx7LH5WqX+uVjwlodyKjCqMWOevqnonwab8OTy\n6JsNMpqRxjI3ftWoKtkH3N8uihLbYS3N+et3H0J2HsF03lC3DK7hirBm4FXw\nG3oOLFAIPCXl0MVvgi8MeHMV8veHUujSJM3+8mCTb4DWtEoION5o0nj1PsQ3\nBuRXGo0D8N+6fY9DOD5Crrlfk1iwq1kmIS1mep0WeVdJe/qCshISWfUFvvo1\n2sEICzdDL5LYxCkZz+umt7Tk2qUvl1Rk+Srg8tmseb2f4VkUTeUPgClmM1SC\nzYIwM1ECMgWrawe+IvCITKqxtWOvH+YN9Ha78a12OD0qKC4zNKOM6DWG/FnO\n+gVscgAOOj36HnNDsHZxgM0cPK8Tp3UBYQfA8qkeH80CdkH9v9qOJIaHuDfq\nVtmn58iIJIP1OeMBbCZsV4MlrrkxgTS5NNxqpL7ISEugUw0slQ2UNaRAbspz\nshyVgGJEvUtK8O4hd3kEfl1niDCJCOzVur/k9lwOei2NmlbsMaadmw8GNDUn\nuFxzroPZRNLrwmYXtiqVYiCpswm7UysPJQkOq/MbT2cIlNp/bMcoxW98O7N7\n5Om3\r\n=+uN1\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICW+c4FIp00ZbLaGmmHucKY3fZi+mAiNhHROBe4aE4hZAiEAz8vaJJ5GanFn7mb650vFI+CnMGT5PMTYPVRJAIGqBfg="}]},"_npmUser":{"name":"dsinni","email":"dsinni@gmail.com"},"directories":{},"maintainers":[{"name":"dsinni","email":"dsinni@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/connect-history-api-fallback_1.6.0_1632779720506_0.035348301893204814"},"_hasShrinkwrap":false}},"time":{"created":"2021-09-27T21:55:20.406Z","1.6.0":"2021-09-27T21:55:20.691Z","modified":"2022-04-05T05:44:54.803Z"},"maintainers":[{"name":"dsinni","email":"dsinni@gmail.com"}],"description":"Provides a fallback for non-existing directories so that the HTML 5 history API can be used.","homepage":"https://github.com/dsinni/connect-history-api-fallback#readme","repository":{"type":"git","url":"git+ssh://git@github.com/dsinni/connect-history-api-fallback.git"},"contributors":[{"name":"Craig Myles","email":"cr@igmyles.com","url":"http://www.craigmyles.com"}],"author":{"name":"Ben Ripkens","email":"bripkens@gmail.com"},"bugs":{"url":"https://github.com/dsinni/connect-history-api-fallback/issues"},"license":"MIT","readme":"<h1 align=\"center\">connect-history-api-fallback</h1>\r\n<p align=\"center\">Middleware to proxy requests through a specified index page, useful for Single Page Applications that utilise the HTML5 History API.</p>\r\n\r\n[![Build Status](https://travis-ci.org/bripkens/connect-history-api-fallback.svg?branch=master)](https://travis-ci.org/bripkens/connect-history-api-fallback)\r\n[![Dependency Status](https://david-dm.org/bripkens/connect-history-api-fallback/master.svg)](https://david-dm.org/bripkens/connect-history-api-fallback/master)\r\n\r\n[![NPM](https://nodei.co/npm/connect-history-api-fallback.png?downloads=true&downloadRank=true)](https://nodei.co/npm/connect-history-api-fallback/)\r\n\r\n\r\n<h2>Table of Contents</h2>\r\n\r\n<!-- TOC depthFrom:2 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->\r\n\r\n- [Introduction](#introduction)\r\n- [Usage](#usage)\r\n- [Options](#options)\r\n\t- [index](#index)\r\n\t- [rewrites](#rewrites)\r\n\t- [verbose](#verbose)\r\n\t- [htmlAcceptHeaders](#htmlacceptheaders)\r\n\t- [disableDotRule](#disabledotrule)\r\n\r\n<!-- /TOC -->\r\n\r\n## Introduction\r\n\r\nSingle Page Applications (SPA) typically only utilise one index file that is\r\naccessible by web browsers: usually `index.html`. Navigation in the application\r\nis then commonly handled using JavaScript with the help of the\r\n[HTML5 History API](http://www.w3.org/html/wg/drafts/html/master/single-page.html#the-history-interface).\r\nThis results in issues when the user hits the refresh button or is directly\r\naccessing a page other than the landing page, e.g. `/help` or `/help/online`\r\nas the web server bypasses the index file to locate the file at this location.\r\nAs your application is a SPA, the web server will fail trying to retrieve the file and return a *404 - Not Found*\r\nmessage to the user.\r\n\r\nThis tiny middleware addresses some of the issues. Specifically, it will change\r\nthe requested location to the index you specify (default being `/index.html`)\r\nwhenever there is a request which fulfills the following criteria:\r\n\r\n 1. The request is a GET request\r\n 2. which accepts `text/html`,\r\n 3. is not a direct file request, i.e. the requested path does not contain a\r\n    `.` (DOT) character and\r\n 4. does not match a pattern provided in options.rewrites (see options below)\r\n\r\n## Usage\r\n\r\nThe middleware is available through NPM and can easily be added.\r\n\r\n```\r\nnpm install --save connect-history-api-fallback\r\n```\r\n\r\nImport the library\r\n\r\n```javascript\r\nvar history = require('connect-history-api-fallback');\r\n```\r\n\r\nNow you only need to add the middleware to your application like so\r\n\r\n```javascript\r\nvar connect = require('connect');\r\n\r\nvar app = connect()\r\n  .use(history())\r\n  .listen(3000);\r\n```\r\n\r\nOf course you can also use this piece of middleware with express:\r\n\r\n```javascript\r\nvar express = require('express');\r\n\r\nvar app = express();\r\napp.use(history());\r\n```\r\n\r\n## Options\r\nYou can optionally pass options to the library when obtaining the middleware\r\n\r\n```javascript\r\nvar middleware = history({});\r\n```\r\n\r\n### index\r\nOverride the index (default `/index.html`). This is the request path that will be used when the middleware identifies that the request path needs to be rewritten.\r\n\r\nThis is not the path to a file on disk. Instead it is the HTTP request path. Downstream connect/express middleware is responsible to turn this rewritten HTTP request path into actual responses, e.g. by reading a file from disk.\r\n\r\n```javascript\r\nhistory({\r\n  index: '/default.html'\r\n});\r\n```\r\n\r\n### rewrites\r\nOverride the index when the request url matches a regex pattern. You can either rewrite to a static string or use a function to transform the incoming request.\r\n\r\nThe following will rewrite a request that matches the `/\\/soccer/` pattern to `/soccer.html`.\r\n```javascript\r\nhistory({\r\n  rewrites: [\r\n    { from: /\\/soccer/, to: '/soccer.html'}\r\n  ]\r\n});\r\n```\r\n\r\nAlternatively functions can be used to have more control over the rewrite process. For instance, the following listing shows how requests to `/libs/jquery/jquery.1.12.0.min.js` and the like can be routed to `./bower_components/libs/jquery/jquery.1.12.0.min.js`. You can also make use of this if you have an API version in the URL path.\r\n```javascript\r\nhistory({\r\n  rewrites: [\r\n    {\r\n      from: /^\\/libs\\/.*$/,\r\n      to: function(context) {\r\n        return '/bower_components' + context.parsedUrl.pathname;\r\n      }\r\n    }\r\n  ]\r\n});\r\n```\r\n\r\nThe function will always be called with a context object that has the following properties:\r\n\r\n - **parsedUrl**: Information about the URL as provided by the [URL module's](https://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost) `url.parse`.\r\n - **match**: An Array of matched results as provided by `String.match(...)`.\r\n - **request**: The HTTP request object.\r\n\r\n\r\n### verbose\r\nThis middleware does not log any information by default. If you wish to activate logging, then you can do so via the `verbose` option or by specifying a logger function.\r\n\r\n```javascript\r\nhistory({\r\n  verbose: true\r\n});\r\n```\r\n\r\nAlternatively use your own logger\r\n\r\n```javascript\r\nhistory({\r\n  logger: console.log.bind(console)\r\n});\r\n```\r\n\r\n### htmlAcceptHeaders\r\nOverride the default `Accepts:` headers that are queried when matching HTML content requests (Default: `['text/html', '*/*']`).\r\n\r\n```javascript\r\nhistory({\r\n  htmlAcceptHeaders: ['text/html', 'application/xhtml+xml']\r\n})\r\n```\r\n\r\n### disableDotRule\r\nDisables the dot rule mentioned above:\r\n\r\n> […] is not a direct file request, i.e. the requested path does not contain a `.` (DOT) character […]\r\n\r\n```javascript\r\nhistory({\r\n  disableDotRule: true\r\n})\r\n```\r\n","readmeFilename":"README.md"}