Gathering detailed insights and metrics for connect-history-api-fallback
Gathering detailed insights and metrics for connect-history-api-fallback
Gathering detailed insights and metrics for connect-history-api-fallback
Gathering detailed insights and metrics for connect-history-api-fallback
@types/connect-history-api-fallback
TypeScript definitions for connect-history-api-fallback
koa-connect-history-api-fallback
Koa adapter for connect-history-api-fallback
koa2-history-api-fallback
base on connect-history-api-fallback
@types/connect-history-api-fallback-exclusions
TypeScript definitions for connect-history-api-fallback-exclusions
Fallback to index.html for applications that are using the HTML 5 history API
npm install connect-history-api-fallback
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,830 Stars
92 Commits
143 Forks
26 Watching
1 Branches
11 Contributors
Updated on 27 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-4.4%
2,639,720
Compared to previous day
Last week
2.6%
13,887,503
Compared to previous week
Last month
12.4%
57,545,204
Compared to previous month
Last year
0.3%
635,502,790
Compared to previous year
Middleware to proxy requests through a specified index page, useful for Single Page Applications that utilise the HTML5 History API.
Single Page Applications (SPA) typically only utilise one index file that is
accessible by web browsers: usually index.html
. Navigation in the application
is then commonly handled using JavaScript with the help of the
HTML5 History API.
This results in issues when the user hits the refresh button or is directly
accessing a page other than the landing page, e.g. /help
or /help/online
as the web server bypasses the index file to locate the file at this location.
As your application is a SPA, the web server will fail trying to retrieve the file and return a 404 - Not Found
message to the user.
This tiny middleware addresses some of the issues. Specifically, it will change
the requested location to the index you specify (default being /index.html
)
whenever there is a request which fulfills the following criteria:
GET
or HEAD
requesttext/html
,.
(DOT) character andThe middleware is available through NPM and can easily be added.
npm install --save connect-history-api-fallback
Import the library
1var history = require('connect-history-api-fallback');
Now you only need to add the middleware to your application like so
1var connect = require('connect'); 2 3var app = connect() 4 .use(history()) 5 .listen(3000);
Of course you can also use this piece of middleware with express:
1var express = require('express'); 2 3var app = express(); 4app.use(history());
You can optionally pass options to the library when obtaining the middleware
1var middleware = history({});
Override 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.
This 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.
1history({ 2 index: '/default.html' 3});
Override 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.
The following will rewrite a request that matches the /\/soccer/
pattern to /soccer.html
.
1history({ 2 rewrites: [ 3 { from: /\/soccer/, to: '/soccer.html'} 4 ] 5});
Alternatively 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.
1history({ 2 rewrites: [ 3 { 4 from: /^\/libs\/.*$/, 5 to: function(context) { 6 return '/bower_components' + context.parsedUrl.pathname; 7 } 8 } 9 ] 10});
The function will always be called with a context object that has the following properties:
url.parse
.String.match(...)
.This 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.
1history({ 2 verbose: true 3});
Alternatively use your own logger
1history({ 2 logger: console.log.bind(console) 3});
Override the default Accepts:
headers that are queried when matching HTML content requests (Default: ['text/html', '*/*']
).
1history({ 2 htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'] 3})
Disables the dot rule mentioned above:
[…] is not a direct file request, i.e. the requested path does not contain a
.
(DOT) character […]
1history({ 2 disableDotRule: true 3})
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 7/24 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
41 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More