Socket
Socket
Sign inDemoInstall

connect-history-api-fallback

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-history-api-fallback

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


Version published
Weekly downloads
9.9M
decreased by-21.37%
Maintainers
1
Weekly downloads
 
Created

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 13 Oct 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc