forked from enviPath/enviPy
Current Dev State
This commit is contained in:
26
static/js/ketcher2/node_modules/connect-pushstate/index.js
generated
vendored
Normal file
26
static/js/ketcher2/node_modules/connect-pushstate/index.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
var url = require('url');
|
||||
|
||||
module.exports = function(options) {
|
||||
options = options || {};
|
||||
|
||||
var root = options.root || '/';
|
||||
var allow = options.allow ? new RegExp(options.allow) : false;
|
||||
var disallow = options.disallow ? new RegExp(options.disallow) : false;
|
||||
|
||||
return function pushState(req, res, next) {
|
||||
var pathname = url.parse(req.url).pathname;
|
||||
var allowed = allow ? allow.test(pathname) : false;
|
||||
var disallowed = disallow ? disallow.test(pathname) : false;
|
||||
var hasFileExtension = !!(path.extname(pathname));
|
||||
|
||||
if (allowed || (!disallowed && hasFileExtension)) {
|
||||
next();
|
||||
} else {
|
||||
req.url = root;
|
||||
next();
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user