Template Upload
This commit is contained in:
10
node_modules/connect-history-api-fallback/.eslintrc
generated
vendored
Normal file
10
node_modules/connect-history-api-fallback/.eslintrc
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
env:
|
||||
node: true
|
||||
|
||||
rules:
|
||||
brace-style: [2, '1tbs', { 'allowSingleLine': true }]
|
||||
strict: [2, 'global']
|
||||
max-len: [2, 80, 4]
|
||||
no-use-before-define: [2, 'nofunc']
|
||||
quotes: [2, 'single', 'avoid-escape']
|
18
node_modules/connect-history-api-fallback/.npmignore
generated
vendored
Normal file
18
node_modules/connect-history-api-fallback/.npmignore
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
node_modules
|
||||
|
||||
### Node.gitignore
|
||||
|
||||
lib-cov
|
||||
*.seed
|
||||
*.log
|
||||
*.csv
|
||||
*.dat
|
||||
*.out
|
||||
*.pid
|
||||
*.gz
|
||||
|
||||
pids
|
||||
logs
|
||||
results
|
||||
|
||||
npm-debug.log
|
9
node_modules/connect-history-api-fallback/.travis.yml
generated
vendored
Normal file
9
node_modules/connect-history-api-fallback/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- "6"
|
||||
- "5"
|
||||
- "4"
|
||||
- "iojs"
|
||||
- "0.12"
|
||||
- "0.10"
|
19
node_modules/connect-history-api-fallback/CHANGELOG.md
generated
vendored
Normal file
19
node_modules/connect-history-api-fallback/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# Changelog
|
||||
|
||||
## v1.3.0
|
||||
- Allow disabling of the `.` (DOT) rule via the `disableDotRule` option.
|
||||
|
||||
## v1.2.0
|
||||
- Support definition of custom HTML `Accept` header values. Contributed by @cgmartin.
|
||||
|
||||
## v1.1.0
|
||||
- Rewrite rules are now applied before the request URL is checked for dots.
|
||||
- Rewrite rules can be defined as functions to have greater control over the `dot rule`.
|
||||
|
||||
## v1.0.0
|
||||
This version introduces a fair amount of breaking changes. Specifically, instances of the historyApiFallback need to be created via the exported function. Previously, this was not necessary.
|
||||
|
||||
- **Breaking:** Support multiple instances of the historyApiFallback middleware with different configurations.
|
||||
- **Breaking:** Loggers are configured per historyApiFallback middleware instance (see `README.md`).
|
||||
- The fallback index HTML file can be configured. Default is `/index.html`.
|
||||
- Additional rewrite rules can be defined via regular expressions.
|
21
node_modules/connect-history-api-fallback/LICENSE
generated
vendored
Normal file
21
node_modules/connect-history-api-fallback/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2012 Ben Ripkens http://bripkens.de
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
147
node_modules/connect-history-api-fallback/README.md
generated
vendored
Normal file
147
node_modules/connect-history-api-fallback/README.md
generated
vendored
Normal file
@ -0,0 +1,147 @@
|
||||
<h1 align="center">connect-history-api-fallback</h1>
|
||||
<p align="center">Middleware to proxy requests through a specified index page, useful for Single Page Applications that utilise the HTML5 History API.</p>
|
||||
|
||||
[](https://travis-ci.org/bripkens/connect-history-api-fallback)
|
||||
[](https://david-dm.org/bripkens/connect-history-api-fallback/master)
|
||||
|
||||
[](https://nodei.co/npm/connect-history-api-fallback/)
|
||||
|
||||
## Introduction
|
||||
|
||||
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](http://www.w3.org/html/wg/drafts/html/master/single-page.html#the-history-interface).
|
||||
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:
|
||||
|
||||
1. The request is a GET request
|
||||
2. which accepts `text/html`,
|
||||
3. is not a direct file request, i.e. the requested path does not contain a
|
||||
`.` (DOT) character and
|
||||
4. does not match a pattern provided in options.rewrites (see options below)
|
||||
|
||||
## Usage
|
||||
|
||||
The middleware is available through NPM and can easily be added.
|
||||
|
||||
```
|
||||
npm install --save connect-history-api-fallback
|
||||
```
|
||||
|
||||
Import the library
|
||||
|
||||
```javascript
|
||||
var history = require('connect-history-api-fallback');
|
||||
```
|
||||
|
||||
Now you only need to add the middleware to your application like so
|
||||
|
||||
```javascript
|
||||
var connect = require('connect');
|
||||
|
||||
var app = connect()
|
||||
.use(history())
|
||||
.listen(3000);
|
||||
```
|
||||
|
||||
Of course you can also use this piece of middleware with express:
|
||||
|
||||
```javascript
|
||||
var express = require('express');
|
||||
|
||||
var app = express();
|
||||
app.use(history());
|
||||
```
|
||||
|
||||
## Options
|
||||
You can optionally pass options to the library when obtaining the middleware
|
||||
|
||||
```javascript
|
||||
var middleware = history({});
|
||||
```
|
||||
|
||||
### index
|
||||
Override the index (default `/index.html`)
|
||||
|
||||
```javascript
|
||||
history({
|
||||
index: '/default.html'
|
||||
});
|
||||
```
|
||||
|
||||
### rewrites
|
||||
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`.
|
||||
```javascript
|
||||
history({
|
||||
rewrites: [
|
||||
{ from: /\/soccer/, to: '/soccer.html'}
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
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.
|
||||
```javascript
|
||||
history({
|
||||
rewrites: [
|
||||
{
|
||||
from: /^\/libs\/.*$/,
|
||||
to: function(context) {
|
||||
return '/bower_components' + context.parsedUrl.pathname;
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
The function will always be called with a context object that has the following properties:
|
||||
|
||||
- **parsedUrl**: Information about the URL as provided by the [URL module's](https://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost) `url.parse`.
|
||||
- **match**: An Array of matched results as provided by `String.match(...)`.
|
||||
|
||||
|
||||
### verbose
|
||||
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.
|
||||
|
||||
```javascript
|
||||
history({
|
||||
verbose: true
|
||||
});
|
||||
```
|
||||
|
||||
Alternatively use your own logger
|
||||
|
||||
```javascript
|
||||
history({
|
||||
logger: console.log.bind(console)
|
||||
});
|
||||
```
|
||||
|
||||
### htmlAcceptHeaders
|
||||
Override the default `Accepts:` headers that are queried when matching HTML content requests (Default: `['text/html', '*/*']`).
|
||||
|
||||
```javascript
|
||||
history({
|
||||
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml']
|
||||
})
|
||||
```
|
||||
|
||||
### disableDotRule
|
||||
Disables the dot rule mentioned above:
|
||||
|
||||
> […] is not a direct file request, i.e. the requested path does not contain a `.` (DOT) character […]
|
||||
|
||||
```javascript
|
||||
history({
|
||||
disableDotRule: true
|
||||
})
|
||||
```
|
107
node_modules/connect-history-api-fallback/lib/index.js
generated
vendored
Normal file
107
node_modules/connect-history-api-fallback/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
var url = require('url');
|
||||
|
||||
exports = module.exports = function historyApiFallback(options) {
|
||||
options = options || {};
|
||||
var logger = getLogger(options);
|
||||
|
||||
return function(req, res, next) {
|
||||
var headers = req.headers;
|
||||
if (req.method !== 'GET') {
|
||||
logger(
|
||||
'Not rewriting',
|
||||
req.method,
|
||||
req.url,
|
||||
'because the method is not GET.'
|
||||
);
|
||||
return next();
|
||||
} else if (!headers || typeof headers.accept !== 'string') {
|
||||
logger(
|
||||
'Not rewriting',
|
||||
req.method,
|
||||
req.url,
|
||||
'because the client did not send an HTTP accept header.'
|
||||
);
|
||||
return next();
|
||||
} else if (headers.accept.indexOf('application/json') === 0) {
|
||||
logger(
|
||||
'Not rewriting',
|
||||
req.method,
|
||||
req.url,
|
||||
'because the client prefers JSON.'
|
||||
);
|
||||
return next();
|
||||
} else if (!acceptsHtml(headers.accept, options)) {
|
||||
logger(
|
||||
'Not rewriting',
|
||||
req.method,
|
||||
req.url,
|
||||
'because the client does not accept HTML.'
|
||||
);
|
||||
return next();
|
||||
}
|
||||
|
||||
var parsedUrl = url.parse(req.url);
|
||||
var rewriteTarget;
|
||||
options.rewrites = options.rewrites || [];
|
||||
for (var i = 0; i < options.rewrites.length; i++) {
|
||||
var rewrite = options.rewrites[i];
|
||||
var match = parsedUrl.pathname.match(rewrite.from);
|
||||
if (match !== null) {
|
||||
rewriteTarget = evaluateRewriteRule(parsedUrl, match, rewrite.to);
|
||||
logger('Rewriting', req.method, req.url, 'to', rewriteTarget);
|
||||
req.url = rewriteTarget;
|
||||
return next();
|
||||
}
|
||||
}
|
||||
|
||||
if (parsedUrl.pathname.indexOf('.') !== -1 &&
|
||||
options.disableDotRule !== true) {
|
||||
logger(
|
||||
'Not rewriting',
|
||||
req.method,
|
||||
req.url,
|
||||
'because the path includes a dot (.) character.'
|
||||
);
|
||||
return next();
|
||||
}
|
||||
|
||||
rewriteTarget = options.index || '/index.html';
|
||||
logger('Rewriting', req.method, req.url, 'to', rewriteTarget);
|
||||
req.url = rewriteTarget;
|
||||
next();
|
||||
};
|
||||
};
|
||||
|
||||
function evaluateRewriteRule(parsedUrl, match, rule) {
|
||||
if (typeof rule === 'string') {
|
||||
return rule;
|
||||
} else if (typeof rule !== 'function') {
|
||||
throw new Error('Rewrite rule can only be of type string of function.');
|
||||
}
|
||||
|
||||
return rule({
|
||||
parsedUrl: parsedUrl,
|
||||
match: match
|
||||
});
|
||||
}
|
||||
|
||||
function acceptsHtml(header, options) {
|
||||
options.htmlAcceptHeaders = options.htmlAcceptHeaders || ['text/html', '*/*'];
|
||||
for (var i = 0; i < options.htmlAcceptHeaders.length; i++) {
|
||||
if (header.indexOf(options.htmlAcceptHeaders[i]) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getLogger(options) {
|
||||
if (options && options.logger) {
|
||||
return options.logger;
|
||||
} else if (options && options.verbose) {
|
||||
return console.log.bind(console);
|
||||
}
|
||||
return function(){};
|
||||
}
|
98
node_modules/connect-history-api-fallback/package.json
generated
vendored
Normal file
98
node_modules/connect-history-api-fallback/package.json
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"connect-history-api-fallback@^1.2.0",
|
||||
"C:\\Users\\x2mjbyrn\\Source\\Repos\\Skeleton\\node_modules\\lite-server"
|
||||
]
|
||||
],
|
||||
"_from": "connect-history-api-fallback@>=1.2.0-0 <2.0.0-0",
|
||||
"_id": "connect-history-api-fallback@1.3.0",
|
||||
"_inCache": true,
|
||||
"_location": "/connect-history-api-fallback",
|
||||
"_nodeVersion": "6.2.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-12-west.internal.npmjs.com",
|
||||
"tmp": "tmp/connect-history-api-fallback-1.3.0.tgz_1470552836120_0.7486736204009503"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "bripkens.dev@gmail.com",
|
||||
"name": "bripkens"
|
||||
},
|
||||
"_npmVersion": "3.8.9",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "connect-history-api-fallback",
|
||||
"raw": "connect-history-api-fallback@^1.2.0",
|
||||
"rawSpec": "^1.2.0",
|
||||
"scope": null,
|
||||
"spec": ">=1.2.0-0 <2.0.0-0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/browser-sync-ui",
|
||||
"/lite-server"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/connect-history-api-fallback/-/connect-history-api-fallback-1.3.0.tgz",
|
||||
"_shasum": "e51d17f8f0ef0db90a64fdb47de3051556e9f169",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "connect-history-api-fallback@^1.2.0",
|
||||
"_where": "C:\\Users\\x2mjbyrn\\Source\\Repos\\Skeleton\\node_modules\\lite-server",
|
||||
"author": {
|
||||
"email": "bripkens.dev@gmail.com",
|
||||
"name": "Ben Ripkens",
|
||||
"url": "http://bripkens.de"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/bripkens/connect-history-api-fallback/issues"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Craig Myles",
|
||||
"email": "cr@igmyles.com",
|
||||
"url": "http://www.craigmyles.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {},
|
||||
"description": "Provides a fallback for non-existing directories so that the HTML 5 history API can be used.",
|
||||
"devDependencies": {
|
||||
"eslint": "^0.18.0",
|
||||
"nodeunit": "^0.9.1",
|
||||
"sinon": "^1.14.1"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "e51d17f8f0ef0db90a64fdb47de3051556e9f169",
|
||||
"tarball": "https://registry.npmjs.org/connect-history-api-fallback/-/connect-history-api-fallback-1.3.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
},
|
||||
"gitHead": "709252d1b7afbf4b29748ec9a881684603d01f97",
|
||||
"homepage": "https://github.com/bripkens/connect-history-api-fallback#readme",
|
||||
"installable": true,
|
||||
"keyswords": [
|
||||
"connect",
|
||||
"fallback",
|
||||
"history api",
|
||||
"html5",
|
||||
"spa"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "bripkens",
|
||||
"email": "bripkens.dev@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "connect-history-api-fallback",
|
||||
"optionalDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/bripkens/connect-history-api-fallback.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "eslint lib/index.js test/index_test.js && nodeunit test/index_test.js"
|
||||
},
|
||||
"version": "1.3.0"
|
||||
}
|
250
node_modules/connect-history-api-fallback/test/index_test.js
generated
vendored
Normal file
250
node_modules/connect-history-api-fallback/test/index_test.js
generated
vendored
Normal file
@ -0,0 +1,250 @@
|
||||
'use strict';
|
||||
|
||||
var sinon = require('sinon');
|
||||
var historyApiFallback = require('../lib');
|
||||
|
||||
var tests = module.exports = {};
|
||||
|
||||
var middleware;
|
||||
var req = null;
|
||||
var requestedUrl;
|
||||
var next;
|
||||
|
||||
tests.setUp = function(done) {
|
||||
middleware = historyApiFallback();
|
||||
requestedUrl = '/foo';
|
||||
req = {
|
||||
method: 'GET',
|
||||
url: requestedUrl,
|
||||
headers: {
|
||||
accept: 'text/html, */*'
|
||||
}
|
||||
};
|
||||
next = sinon.stub();
|
||||
|
||||
done();
|
||||
};
|
||||
|
||||
|
||||
['POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS'].forEach(function(method) {
|
||||
tests['should ignore ' + method + ' requests'] = function(test) {
|
||||
req.method = method;
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, requestedUrl);
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
tests['should ignore requests that do not accept html'] = function(test) {
|
||||
req.headers.accept = 'application/json';
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, requestedUrl);
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
|
||||
|
||||
tests['should ignore file requests'] = function(test) {
|
||||
var expected = req.url = 'js/app.js';
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, expected);
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
|
||||
|
||||
tests['should rewrite requests when the . rule is disabled'] = function(test) {
|
||||
req.url = 'js/app.js';
|
||||
middleware = historyApiFallback({
|
||||
disableDotRule: true
|
||||
});
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, '/index.html');
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
|
||||
|
||||
tests['should take JSON preference into account'] = function(test) {
|
||||
req.headers.accept = 'application/json, text/plain, */*';
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, requestedUrl);
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
|
||||
|
||||
tests['should rewrite valid requests'] = function(test) {
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, '/index.html');
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
|
||||
tests['should not fail for missing HTTP accept header'] = function(test) {
|
||||
delete req.headers.accept;
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, requestedUrl);
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
|
||||
tests['should not fail for missing headers object'] = function(test) {
|
||||
delete req.headers;
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, requestedUrl);
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
|
||||
tests['should work in verbose mode'] = function(test) {
|
||||
var expected = req.url = 'js/app.js';
|
||||
middleware = historyApiFallback({
|
||||
verbose: true
|
||||
});
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, expected);
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
|
||||
tests['should work with a custom logger'] = function(test) {
|
||||
var expected = req.url = 'js/app.js';
|
||||
var logger = sinon.stub();
|
||||
middleware = historyApiFallback({
|
||||
logger: logger
|
||||
});
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, expected);
|
||||
test.ok(next.called);
|
||||
test.ok(logger.calledOnce);
|
||||
test.done();
|
||||
};
|
||||
|
||||
tests['should rewrite requested path according to rules'] = function(test) {
|
||||
req.url = '/soccer';
|
||||
middleware = historyApiFallback({
|
||||
rewrites: [
|
||||
{from: /\/soccer/, to: '/soccer.html'}
|
||||
]
|
||||
});
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, '/soccer.html');
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
|
||||
tests['should support functions as rewrite rule'] = function(test) {
|
||||
middleware = historyApiFallback({
|
||||
rewrites: [
|
||||
{
|
||||
from: /^\/libs\/(.*)$/,
|
||||
to: function(context) {
|
||||
return './bower_components' + context.parsedUrl.pathname;
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
req.url = '/libs/jquery/jquery.1.12.0.min.js';
|
||||
middleware(req, null, next);
|
||||
test.equal(req.url, './bower_components/libs/jquery/jquery.1.12.0.min.js');
|
||||
test.ok(next.called);
|
||||
|
||||
next = sinon.stub();
|
||||
var expected = req.url = '/js/main.js';
|
||||
middleware(req, null, next);
|
||||
test.equal(req.url, expected);
|
||||
test.ok(next.called);
|
||||
|
||||
test.done();
|
||||
};
|
||||
|
||||
tests['should test rewrite rules'] = function(test) {
|
||||
req.url = '/socer';
|
||||
middleware = historyApiFallback({
|
||||
rewrites: [
|
||||
{from: /\/soccer/, to: '/soccer.html'}
|
||||
]
|
||||
});
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, '/index.html');
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
|
||||
tests['should support custom index file'] = function(test) {
|
||||
var index = 'default.html';
|
||||
req.url = '/socer';
|
||||
middleware = historyApiFallback({
|
||||
index: index
|
||||
});
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, index);
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
|
||||
tests['should accept html requests based on headers option'] = function(test) {
|
||||
req.headers.accept = '*/*';
|
||||
middleware = historyApiFallback({
|
||||
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml']
|
||||
});
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, requestedUrl);
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
||||
|
||||
tests['should support custom rewrite rules'] = function(test) {
|
||||
req.headers.accept = '*/*';
|
||||
var url = '/app/login/app.js';
|
||||
req.url = url;
|
||||
middleware = historyApiFallback({
|
||||
rewrites: [
|
||||
{
|
||||
from: /\/app\/login/,
|
||||
to: function onMatch(ctx) {
|
||||
if (ctx.parsedUrl.path.indexOf('.js')) {
|
||||
return ctx.parsedUrl.href;
|
||||
}
|
||||
return '/app/login/index.html';
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
middleware(req, null, next);
|
||||
|
||||
test.equal(req.url, url);
|
||||
test.ok(next.called);
|
||||
test.done();
|
||||
};
|
Reference in New Issue
Block a user