Gathering detailed insights and metrics for @stipsan/express-history-api-fallback
Gathering detailed insights and metrics for @stipsan/express-history-api-fallback
npm install @stipsan/express-history-api-fallback
Typescript
Module System
Node Version
NPM Version
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
648
Last Day
1
Last Week
3
Last Month
6
Last Year
43
Minified
Minified + Gzipped
Latest Version
2.1.0
Package Id
@stipsan/express-history-api-fallback@2.1.0
Size
2.65 kB
NPM Version
3.7.2
Node Version
5.6.0
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
200%
3
Compared to previous week
Last month
200%
6
Compared to previous month
Last year
-44.9%
43
Compared to previous year
I just needed to use callbacks instead of being limited to res.sendFile as I use React server side rendering instead of a static index.html file.
A tiny, accurate, fast Express middleware for single page apps with client side routing.
Works as a middleware for Express v4.8.0 or later. Can be used as either an application middleware or a router middleware.
1import fallback from 'express-history-api-fallback' 2import express from 'express' 3const app = express() 4const root = `${__dirname}/public` 5app.use(express.static(root)) 6app.use(fallback('index.html', { root }))
Or in ECMAScript 5:
1var fallback = require('express-history-api-fallback') 2var express = require('express') 3var app = express() 4var root = __dirname + '/public' 5app.use(express.static(root)) 6app.use(fallback('index.html', { root: root }))
Returns a middleware for use by Express applications and routers.
Arguments are passed to Response.sendFile() in Express v4.8.0 or later.
Absolute path:
1app.use(fallback(__dirname + '/dist/app.html'))
Relative path:
1app.use(fallback('dist/app.html', { root: __dirname }))
Location of the HTML file containing single page app entry point.
Unless the root
option is set in the options
object, path
must be an absolute path of the file.
Valid options are maxAge
, root
, lastModified
, headers
, and dotfiles
. See Response.sendFile() for details.
Yes, but this implementation is much better.
index.html
for POST
or other requests.res.sendFile()
in Express >=4.8.0
do the heavy lifting of serving the file.See the blog post "Single Page App Routing with Express & Node.js" for an overview of the problems with alternative middlewares.
No vulnerabilities found.
No security vulnerabilities found.