/ stream.nieuweinstituut.nl / node_modules / express-history-api-fallback /

[ICO]NameLast modifiedSizeDescription
[PARENTDIR]Parent Directory  -  
[DIR]dist/2 years ago -  
[TXT]README.md8 years ago2.7Kd768d73 docs [كارل مبارك]
[   ]app.json8 years ago 86  
[   ]node-license-validator.json10 years ago 78  
[   ]package.json2 years ago2.8K3e510ca test new git [كارل مبارك]
README.md

express-history-api-fallback

A tiny, accurate, fast Express middleware for single page apps with client side routing.

Build Status codecov.io

NPM

Works as a middleware for Express. Can be used as either an application middleware or a router middleware.

import fallback from 'express-history-api-fallback'
import express from 'express'
const app = express()
const root = `${__dirname}/public`
app.use(express.static(root))
app.use(fallback('index.html', { root }))

Or in ECMAScript 5:

var fallback = require('express-history-api-fallback')
var express = require('express')
var app = express()
var root = __dirname + '/public'
app.use(express.static(root))
app.use(fallback('index.html', { root: root }))

fallback(path[, options])

Returns a middleware for use by Express applications and routers.

Arguments are passed to res.sendFile() in express@>=v4.8.0, or res.sendfile() otherwise.

Absolute path:

app.use(fallback(__dirname + '/dist/app.html'))

Relative path:

app.use(fallback('dist/app.html', { root: __dirname }))

path

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.

options

Valid options are maxAge, root, lastModified, headers, and dotfiles. See Response.sendFile() for details. Note that only maxAge and root are supported with express@<4.8.

But doesn't this already exist?

Yes, but this implementation is much better.

See the blog post "Single Page App Routing with Express & Node.js" for an overview of the problems with alternative middlewares.

Apache/2.4.38 (Debian) Server at www.karls.computer Port 80