🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

connect-history-api-fallback

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
c

connect-history-api-fallback

Provides a fallback for non-existing directories so that the HTML 5 history API can be used.

2.0.0
latest
100

Supply Chain Security

100

Vulnerability

100

Quality

76

Maintenance

100

License

Version published
Weekly downloads
12M
-13.65%
Maintainers
1
Weekly downloads
 
Created
Issues
15

What is connect-history-api-fallback?

The connect-history-api-fallback package is a middleware for Connect and Express-based web servers. It is designed to redirect requests for non-existent files to a specified file, often used in single-page applications (SPAs) where the routing is handled client-side by JavaScript. This allows the server to seamlessly hand off routing responsibilities to the client, ensuring that deep linking works correctly and that users can refresh pages without receiving 404 errors.

What are connect-history-api-fallback's main functionalities?

Basic Usage with Express

This code demonstrates how to integrate connect-history-api-fallback with an Express server. It redirects all requests to the 'public' directory unless the file exists, making it ideal for SPAs.

const express = require('express');
const history = require('connect-history-api-fallback');

const app = express();
app.use(history());
app.use(express.static('public'));

app.listen(3000);

Custom Options

This example shows how to use connect-history-api-fallback with custom options, such as specifying a custom index file and enabling verbose logging for debugging purposes.

const express = require('express');
const history = require('connect-history-api-fallback');

const app = express();
app.use(history({
  index: '/index.html',
  verbose: true
}));
app.use(express.static('public'));

app.listen(3000);

Other packages similar to connect-history-api-fallback

FAQs

Package last updated on 27 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts