forked from svrjs/svrjs
Update to SVR.JS 3.14.2
This commit is contained in:
parent
06712f35b5
commit
9c49df9d87
6 changed files with 28 additions and 120 deletions
54
config.json
54
config.json
|
@ -28,59 +28,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"definingRegex": "/^\\/invoke500\\/\\?/",
|
"definingRegex": "/^\\/testdir_rewritten(?:$|[\\/?#])/",
|
||||||
"replacements": [
|
"replacements": [
|
||||||
{
|
{
|
||||||
"regex": "/\\/invoke500\\/\\?/",
|
"regex": "/^\\/testdir_rewritten($|[\\/?#])/",
|
||||||
"replacement": "/invoke500.svr?"
|
"replacement": "/testdir$1"
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"definingRegex": "/^\\/invoke500\\/.+\\//",
|
|
||||||
"replacements": [
|
|
||||||
{
|
|
||||||
"regex": "/\\/\\?/",
|
|
||||||
"replacement": "&"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"regex": "/invoke500\\//",
|
|
||||||
"replacement": "invoke500.svr?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"regex": "/\\/(?!invoke500.svr?)/",
|
|
||||||
"replacement": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"definingRegex": "/^\\/invoke500\\/.+/",
|
|
||||||
"replacements": [
|
|
||||||
{
|
|
||||||
"regex": "/\\?/",
|
|
||||||
"replacement": "&"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"regex": "/invoke500\\//",
|
|
||||||
"replacement": "invoke500.svr?"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"definingRegex": "/^\\/invoke500\\//",
|
|
||||||
"replacements": [
|
|
||||||
{
|
|
||||||
"regex": "/\\/invoke500\\//",
|
|
||||||
"replacement": "/invoke500.svr"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"definingRegex": "/^\\/invoke500$/",
|
|
||||||
"replacements": [
|
|
||||||
{
|
|
||||||
"regex": "/\\/invoke500/",
|
|
||||||
"replacement": "/invoke500.svr"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
61
index.html
61
index.html
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>SVR.JS 3.14.1</title>
|
<title>SVR.JS 3.14.2</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<style>
|
<style>
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Welcome to SVR.JS 3.14.1</h1>
|
<h1>Welcome to SVR.JS 3.14.2</h1>
|
||||||
<br/>
|
<br/>
|
||||||
<img src="/logo.png" style="width: 256px;" />
|
<img src="/logo.png" style="width: 256px;" />
|
||||||
<br/>
|
<br/>
|
||||||
|
@ -50,59 +50,11 @@
|
||||||
]<br/>
|
]<br/>
|
||||||
},<br/>
|
},<br/>
|
||||||
{<br/>
|
{<br/>
|
||||||
"definingRegex": "/^\\/invoke500\\/\\?/",<br/>
|
"definingRegex": "/^\\/testdir_rewritten(?:$|[\\/?#])/",<br/>
|
||||||
"replacements": [<br/>
|
"replacements": [<br/>
|
||||||
{<br/>
|
{<br/>
|
||||||
"regex": "/\\/invoke500\\/\\?/",<br/>
|
"regex": "/^\\/testdir_rewritten($|[\\/?#])/",<br/>
|
||||||
"replacement": "/invoke500.svr?"<br/>
|
"replacement": "/testdir$1"<br/>
|
||||||
}<br/>
|
|
||||||
]<br/>
|
|
||||||
},<br/>
|
|
||||||
{<br/>
|
|
||||||
"definingRegex": "/^\\/invoke500\\/.+\\//",<br/>
|
|
||||||
"replacements": [<br/>
|
|
||||||
{<br/>
|
|
||||||
"regex": "/\\/\\?/",<br/>
|
|
||||||
"replacement": "&"<br/>
|
|
||||||
},<br/>
|
|
||||||
{<br/>
|
|
||||||
"regex": "/invoke500\\//",<br/>
|
|
||||||
"replacement": "invoke500.svr?"<br/>
|
|
||||||
},<br/>
|
|
||||||
{<br/>
|
|
||||||
"regex": "/\\/(?!invoke500.svr?)/",<br/>
|
|
||||||
"replacement": ""<br/>
|
|
||||||
}<br/>
|
|
||||||
]<br/>
|
|
||||||
},<br/>
|
|
||||||
{<br/>
|
|
||||||
"definingRegex": "/^\\/invoke500\\/.+/",<br/>
|
|
||||||
"replacements": [<br/>
|
|
||||||
{<br/>
|
|
||||||
"regex": "/\\?/",<br/>
|
|
||||||
"replacement": "&"<br/>
|
|
||||||
},<br/>
|
|
||||||
{<br/>
|
|
||||||
"regex": "/invoke500\\//",<br/>
|
|
||||||
"replacement": "invoke500.svr?"<br/>
|
|
||||||
}<br/>
|
|
||||||
]<br/>
|
|
||||||
},<br/>
|
|
||||||
{<br/>
|
|
||||||
"definingRegex": "/^\\/invoke500\\//",<br/>
|
|
||||||
"replacements": [<br/>
|
|
||||||
{<br/>
|
|
||||||
"regex": "/\\/invoke500\\//",<br/>
|
|
||||||
"replacement": "/invoke500.svr"<br/>
|
|
||||||
}<br/>
|
|
||||||
]<br/>
|
|
||||||
},<br/>
|
|
||||||
{<br/>
|
|
||||||
"definingRegex": "/^\\/invoke500$/",<br/>
|
|
||||||
"replacements": [<br/>
|
|
||||||
{<br/>
|
|
||||||
"regex": "/\\/invoke500/",<br/>
|
|
||||||
"replacement": "/invoke500.svr"<br/>
|
|
||||||
}<br/>
|
}<br/>
|
||||||
]<br/>
|
]<br/>
|
||||||
}<br/>
|
}<br/>
|
||||||
|
@ -134,8 +86,7 @@
|
||||||
</div>
|
</div>
|
||||||
<p>Changes:</p>
|
<p>Changes:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Added support for IP-based virtual hosts.</li>
|
<li>Added new SVR.JS mod and server-side JavaScript property: <i>authUser</i>.</li>
|
||||||
<li>Fixed SVR.JS crashes with <i>X-SVR-JS-From-Main-Thread</i> header and unknown client IPs.</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
<br/>
|
<br/>
|
||||||
<a href="/tests.html">Tests</a><br/>
|
<a href="/tests.html">Tests</a><br/>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>SVR.JS 3.14.1 Licenses</title>
|
<title>SVR.JS 3.14.2 Licenses</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<style>
|
<style>
|
||||||
|
@ -12,8 +12,8 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>SVR.JS 3.14.1 Licenses</h1>
|
<h1>SVR.JS 3.14.2 Licenses</h1>
|
||||||
<h2>SVR.JS 3.14.1</h2>
|
<h2>SVR.JS 3.14.2</h2>
|
||||||
<div style="display: inline-block; text-align: left; border-width: 2px; border-style: solid; border-color: gray; padding: 8px;">
|
<div style="display: inline-block; text-align: left; border-width: 2px; border-style: solid; border-color: gray; padding: 8px;">
|
||||||
MIT License<br/>
|
MIT License<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br/>
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br/>
|
||||||
SOFTWARE.<br/>
|
SOFTWARE.<br/>
|
||||||
</div>
|
</div>
|
||||||
<h2>Packages used by SVR.JS 3.14.1</h2>
|
<h2>Packages used by SVR.JS 3.14.2</h2>
|
||||||
<div style="width: 100%; background-color: #ccc; border: 1px solid green; text-align: left; margin: 10px 0;">
|
<div style="width: 100%; background-color: #ccc; border: 1px solid green; text-align: left; margin: 10px 0;">
|
||||||
<div style="float: right;">License: MIT</div>
|
<div style="float: right;">License: MIT</div>
|
||||||
<div style="font-size: 20px;">
|
<div style="font-size: 20px;">
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
// origHref - Original request URL without query (before URL rewriting)
|
// origHref - Original request URL without query (before URL rewriting)
|
||||||
// redirect - Method to redirect.
|
// redirect - Method to redirect.
|
||||||
// parsePostData - Method to parse POST data.
|
// parsePostData - Method to parse POST data.
|
||||||
|
// authUser - Authenticated HTTP user.
|
||||||
//Along with elements added by this implementation:
|
//Along with elements added by this implementation:
|
||||||
// disableEndElseCallbackExecute - Determines execution of elseCallback on end
|
// disableEndElseCallbackExecute - Determines execution of elseCallback on end
|
||||||
// filterHeaders - Removes invalid HTTP/1.0 headers
|
// filterHeaders - Removes invalid HTTP/1.0 headers
|
||||||
|
|
16
svr.js
16
svr.js
|
@ -69,7 +69,7 @@ function deleteFolderRecursive(path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var os = require("os");
|
var os = require("os");
|
||||||
var version = "3.14.1";
|
var version = "3.14.2";
|
||||||
var singlethreaded = false;
|
var singlethreaded = false;
|
||||||
|
|
||||||
if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions
|
if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions
|
||||||
|
@ -1655,7 +1655,7 @@ if (!disableMods) {
|
||||||
if (fs.existsSync(SSJSPath) && fs.statSync(SSJSPath).isFile()) {
|
if (fs.existsSync(SSJSPath) && fs.statSync(SSJSPath).isFile()) {
|
||||||
try {
|
try {
|
||||||
// Prepend necessary modules and variables to the custom server side script
|
// Prepend necessary modules and variables to the custom server side script
|
||||||
var modhead = "var readline = require('readline');\r\nvar os = require('os');\r\nvar http = require('http');\r\nvar url = require('url');\r\nvar fs = require('fs');\r\nvar path = require('path');\r\n" + (hexstrbase64 === undefined ? "" : "var hexstrbase64 = require('../hexstrbase64/index.js');\r\n") + (crypto.__disabled__ === undefined ? "var crypto = require('crypto');\r\nvar https = require('https');\r\n" : "") + "var stream = require('stream');\r\nvar customvar1;\r\nvar customvar2;\r\nvar customvar3;\r\nvar customvar4;\r\n\r\nfunction Mod() {}\r\nMod.prototype.callback = function callback(req, res, serverconsole, responseEnd, href, ext, uobject, search, defaultpage, users, page404, head, foot, fd, elseCallback, configJSON, callServerError, getCustomHeaders, origHref, redirect, parsePostData) {\r\nreturn function () {\r\nvar disableEndElseCallbackExecute = false;\r\nfunction filterHeaders(e){var r={};return Object.keys(e).forEach((function(t){null!==e[t]&&void 0!==e[t]&&(\"object\"==typeof e[t]?r[t]=JSON.parse(JSON.stringify(e[t])):r[t]=e[t])})),r}\r\nfunction checkHostname(e){if(void 0===e||\"*\"==e)return!0;if(req.headers.host&&0==e.indexOf(\"*.\")&&\"*.\"!=e){var r=e.substr(2);if(req.headers.host==r||req.headers.host.indexOf(\".\"+r)==req.headers.host.length-r.length-1)return!0}else if(req.headers.host&&req.headers.host==e)return!0;return!1}\r\nfunction checkHref(e){return href==e||\"win32\"==os.platform()&&href.toLowerCase()==e.toLowerCase()}\r\n";
|
var modhead = "var readline = require('readline');\r\nvar os = require('os');\r\nvar http = require('http');\r\nvar url = require('url');\r\nvar fs = require('fs');\r\nvar path = require('path');\r\n" + (hexstrbase64 === undefined ? "" : "var hexstrbase64 = require('../hexstrbase64/index.js');\r\n") + (crypto.__disabled__ === undefined ? "var crypto = require('crypto');\r\nvar https = require('https');\r\n" : "") + "var stream = require('stream');\r\nvar customvar1;\r\nvar customvar2;\r\nvar customvar3;\r\nvar customvar4;\r\n\r\nfunction Mod() {}\r\nMod.prototype.callback = function callback(req, res, serverconsole, responseEnd, href, ext, uobject, search, defaultpage, users, page404, head, foot, fd, elseCallback, configJSON, callServerError, getCustomHeaders, origHref, redirect, parsePostData, authUser) {\r\nreturn function () {\r\nvar disableEndElseCallbackExecute = false;\r\nfunction filterHeaders(e){var r={};return Object.keys(e).forEach((function(t){null!==e[t]&&void 0!==e[t]&&(\"object\"==typeof e[t]?r[t]=JSON.parse(JSON.stringify(e[t])):r[t]=e[t])})),r}\r\nfunction checkHostname(e){if(void 0===e||\"*\"==e)return!0;if(req.headers.host&&0==e.indexOf(\"*.\")&&\"*.\"!=e){var r=e.substr(2);if(req.headers.host==r||req.headers.host.indexOf(\".\"+r)==req.headers.host.length-r.length-1)return!0}else if(req.headers.host&&req.headers.host==e)return!0;return!1}\r\nfunction checkHref(e){return href==e||\"win32\"==os.platform()&&href.toLowerCase()==e.toLowerCase()}\r\n";
|
||||||
var modfoot = "\r\nif(!disableEndElseCallbackExecute) {\r\ntry{\r\nelseCallback();\r\n} catch(err) {\r\n}\r\n}\r\n}\r\n}\r\nmodule.exports = Mod;";
|
var modfoot = "\r\nif(!disableEndElseCallbackExecute) {\r\ntry{\r\nelseCallback();\r\n} catch(err) {\r\n}\r\n}\r\n}\r\n}\r\nmodule.exports = Mod;";
|
||||||
// Write the modified server side script to the temp folder
|
// Write the modified server side script to the temp folder
|
||||||
fs.writeFileSync(__dirname + "/temp/" + tempServerSideScriptName, modhead + fs.readFileSync(SSJSPath) + modfoot);
|
fs.writeFileSync(__dirname + "/temp/" + tempServerSideScriptName, modhead + fs.readFileSync(SSJSPath) + modfoot);
|
||||||
|
@ -3380,6 +3380,9 @@ if (!cluster.isPrimary) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Authenticated user variable
|
||||||
|
var authUser = null;
|
||||||
|
|
||||||
// URL-related objects.
|
// URL-related objects.
|
||||||
var uobject = parseURL(req.url);
|
var uobject = parseURL(req.url);
|
||||||
var search = uobject.search;
|
var search = uobject.search;
|
||||||
|
@ -3417,7 +3420,7 @@ if (!cluster.isPrimary) {
|
||||||
}
|
}
|
||||||
|
|
||||||
useMods.reverse().forEach(function (modO) {
|
useMods.reverse().forEach(function (modO) {
|
||||||
modFunction = modO.callback(req, res, serverconsole, responseEnd, href, ext, uobject, search, "index.html", users, page404, head, foot, "", modFunction, configJSON, callServerError, getCustomHeaders, origHref, redirect, parsePostData);
|
modFunction = modO.callback(req, res, serverconsole, responseEnd, href, ext, uobject, search, "index.html", users, page404, head, foot, "", modFunction, configJSON, callServerError, getCustomHeaders, origHref, redirect, parsePostData, authUser);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Execute modFunction
|
// Execute modFunction
|
||||||
|
@ -3426,7 +3429,7 @@ if (!cluster.isPrimary) {
|
||||||
|
|
||||||
var vresCalled = false;
|
var vresCalled = false;
|
||||||
|
|
||||||
function vres(req, res, serverconsole, responseEnd, href, ext, uobject, search, defaultpage, users, page404, head, foot, fd, callServerError, getCustomHeaders, origHref, redirect, parsePostData) {
|
function vres(req, res, serverconsole, responseEnd, href, ext, uobject, search, defaultpage, users, page404, head, foot, fd, callServerError, getCustomHeaders, origHref, redirect, parsePostData, authUser) {
|
||||||
return function () {
|
return function () {
|
||||||
if (vresCalled) {
|
if (vresCalled) {
|
||||||
process.emitWarning("elseCallback() invoked multiple times.", {
|
process.emitWarning("elseCallback() invoked multiple times.", {
|
||||||
|
@ -4745,8 +4748,9 @@ if (!cluster.isPrimary) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
serverconsole.reqmessage("Client is logged in as \"" + String(username).replace(/[\r\n]/g, "") + "\".");
|
serverconsole.reqmessage("Client is logged in as \"" + String(username).replace(/[\r\n]/g, "") + "\".");
|
||||||
|
authUser = username;
|
||||||
redirectTrailingSlashes(function () {
|
redirectTrailingSlashes(function () {
|
||||||
modExecute(mods, vres(req, res, serverconsole, responseEnd, href, ext, uobject, search, "index.html", users, page404, head, foot, "", callServerError, getCustomHeaders, origHref, redirect, parsePostData));
|
modExecute(mods, vres(req, res, serverconsole, responseEnd, href, ext, uobject, search, "index.html", users, page404, head, foot, "", callServerError, getCustomHeaders, origHref, redirect, parsePostData, authUser));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -4795,7 +4799,7 @@ if (!cluster.isPrimary) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
redirectTrailingSlashes(function () {
|
redirectTrailingSlashes(function () {
|
||||||
modExecute(mods, vres(req, res, serverconsole, responseEnd, href, ext, uobject, search, "index.html", users, page404, head, foot, "", callServerError, getCustomHeaders, origHref, redirect, parsePostData));
|
modExecute(mods, vres(req, res, serverconsole, responseEnd, href, ext, uobject, search, "index.html", users, page404, head, foot, "", callServerError, getCustomHeaders, origHref, redirect, parsePostData, authUser));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>SVR.JS 3.14.1 Tests</title>
|
<title>SVR.JS 3.14.2 Tests</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<style>
|
<style>
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>SVR.JS 3.14.1 Tests</h1>
|
<h1>SVR.JS 3.14.2 Tests</h1>
|
||||||
<h2>Directory (without trailing slash)</h2>
|
<h2>Directory (without trailing slash)</h2>
|
||||||
<iframe src="/testdir" width="50%" height="300px"></iframe>
|
<iframe src="/testdir" width="50%" height="300px"></iframe>
|
||||||
<h2>Directory (with query)</h2>
|
<h2>Directory (with query)</h2>
|
||||||
|
@ -32,8 +32,8 @@
|
||||||
<iframe src="/hello.svr" width="50%" height="300px"></iframe>
|
<iframe src="/hello.svr" width="50%" height="300px"></iframe>
|
||||||
<h2>Proxy test</h2>
|
<h2>Proxy test</h2>
|
||||||
<iframe src="/proxy.svr/this/hello.svr" width="50%" height="300px" id="proxy"></iframe>
|
<iframe src="/proxy.svr/this/hello.svr" width="50%" height="300px" id="proxy"></iframe>
|
||||||
<h2>URL rewriting test (/invoke500/aprilfools => /invoke500.svr?aprilfools)</h2>
|
<h2>URL rewriting test (/testdir_rewritten => /testdir)</h2>
|
||||||
<iframe src="/invoke500/aprilfools" width="50%" height="300px"></iframe>
|
<iframe src="/testdir_rewritten" width="50%" height="300px"></iframe>
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
<img src="/powered.png" />
|
<img src="/powered.png" />
|
||||||
|
|
Reference in a new issue