connect-history-api-fallback
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The connect-history-api-fallback
is a handy middleware used to proxy requests through a specified index page. Its primary utility is for handling Single Page Applications (SPAs) that make use of the HTML5 History API. It provides a fallback mechanism for non-existing directories, hence enabling the usage of the HTML 5 History API. This prevents issues where the user refreshes the page or directly accesses a page other than the index.html, which would usually result in a 404 Not Found error. Therefore, it changes the requested location to a specified index whenever a GET or HEAD request that accepts text/html is made and is neither a direct file request nor matches a pattern specified in options.rewrites
.
To use connect-history-api-fallback
, it needs to be installed from NPM and added as a middleware to the application. Here is a simple usage example:
// Step 1: Install via NPM
npm install --save connect-history-api-fallback
// Step 2: Import the library
var history = require('connect-history-api-fallback');
// Step 3: Add the middleware to your application
var connect = require('connect');
var app = connect()
.use(history())
.listen(3000);
It can also be incorporated into an express application as follows:
var express = require('express');
var app = express();
app.use(history());
Additionally, options can be passed to the library to override the default settings. These include the index, rewrites, verbosity, htmlAcceptHeaders, and disabling the dot rule.
The documentation for connect-history-api-fallback
can be found in the README file of its GitHub repository, which is located at https://github.com/bripkens/connect-history-api-fallback. The documentation provides a comprehensive overview of the library, outlining its usage, ways to customize it with options, and how to include it in your application. It's a useful resource for anyone looking to leverage this package in their web applications.