forked from svrjs/svrjs
Lint out the codebase
This commit is contained in:
parent
eaafa8cc41
commit
67658ad329
2 changed files with 96 additions and 24 deletions
|
@ -1,4 +1,3 @@
|
||||||
const generateServerString = require("../utils/generateServerString");
|
|
||||||
const svrjsInfo = require("../../svrjs.json");
|
const svrjsInfo = require("../../svrjs.json");
|
||||||
const { name } = svrjsInfo;
|
const { name } = svrjsInfo;
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ function noproxyHandler(req, socket, head) {
|
||||||
if (!socket.destroyed) socket.end("HTTP/1.1 501 Not Implemented\n\n");
|
if (!socket.destroyed) socket.end("HTTP/1.1 501 Not Implemented\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (serverconsoleO, middlewareO) => {
|
module.exports = (serverconsoleO) => {
|
||||||
serverconsole = serverconsoleO;
|
serverconsole = serverconsoleO;
|
||||||
return noproxyHandler;
|
return noproxyHandler;
|
||||||
};
|
};
|
||||||
|
|
117
src/index.js
117
src/index.js
|
@ -21,6 +21,58 @@ try {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let http2 = {};
|
||||||
|
try {
|
||||||
|
http2 = require("http2");
|
||||||
|
if (process.isBun) {
|
||||||
|
try {
|
||||||
|
http2.Http2ServerRequest();
|
||||||
|
} catch (err) {
|
||||||
|
if (
|
||||||
|
err.name == "NotImplementedError" ||
|
||||||
|
err.code == "ERR_NOT_IMPLEMENTED"
|
||||||
|
)
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
http2.__disabled__ = null;
|
||||||
|
http2.createServer = function () {
|
||||||
|
throw new Error("HTTP/2 support is not present");
|
||||||
|
};
|
||||||
|
http2.createSecureServer = function () {
|
||||||
|
throw new Error("HTTP/2 support is not present");
|
||||||
|
};
|
||||||
|
http2.connect = function () {
|
||||||
|
throw new Error("HTTP/2 support is not present");
|
||||||
|
};
|
||||||
|
http2.get = function () {
|
||||||
|
throw new Error("HTTP/2 support is not present");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let crypto = {
|
||||||
|
__disabled__: null,
|
||||||
|
};
|
||||||
|
let https = {
|
||||||
|
createServer: function () {
|
||||||
|
throw new Error("Crypto support is not present");
|
||||||
|
},
|
||||||
|
connect: function () {
|
||||||
|
throw new Error("Crypto support is not present");
|
||||||
|
},
|
||||||
|
get: function () {
|
||||||
|
throw new Error("Crypto support is not present");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
crypto = require("crypto");
|
||||||
|
https = require("https");
|
||||||
|
} catch (err) {
|
||||||
|
http2.createSecureServer = function () {
|
||||||
|
throw new Error("Crypto support is not present");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
process.dirname = __dirname;
|
process.dirname = __dirname;
|
||||||
process.filename = __filename;
|
process.filename = __filename;
|
||||||
|
|
||||||
|
@ -598,20 +650,21 @@ if (process.serverConfig.enableHTTP2 == true) {
|
||||||
requireHostHeader: false,
|
requireHostHeader: false,
|
||||||
key: key,
|
key: key,
|
||||||
cert: cert,
|
cert: cert,
|
||||||
requestCert: configJSON.useClientCertificate,
|
requestCert: process.serverConfig.useClientCertificate,
|
||||||
rejectUnauthorized: configJSON.rejectUnauthorizedClientCertificates,
|
rejectUnauthorized:
|
||||||
ciphers: configJSON.cipherSuite,
|
process.serverConfig.rejectUnauthorizedClientCertificates,
|
||||||
ecdhCurve: configJSON.ecdhCurve,
|
ciphers: process.serverConfig.cipherSuite,
|
||||||
minVersion: configJSON.tlsMinVersion,
|
ecdhCurve: process.serverConfig.ecdhCurve,
|
||||||
maxVersion: configJSON.tlsMaxVersion,
|
minVersion: process.serverConfig.tlsMinVersion,
|
||||||
sigalgs: configJSON.signatureAlgorithms,
|
maxVersion: process.serverConfig.tlsMaxVersion,
|
||||||
settings: configJSON.http2Settings,
|
sigalgs: process.serverConfig.signatureAlgorithms,
|
||||||
|
settings: process.serverConfig.http2Settings,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
server = http2.createServer({
|
server = http2.createServer({
|
||||||
allowHTTP1: true,
|
allowHTTP1: true,
|
||||||
requireHostHeader: false,
|
requireHostHeader: false,
|
||||||
settings: configJSON.http2Settings,
|
settings: process.serverConfig.http2Settings,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -620,13 +673,14 @@ if (process.serverConfig.enableHTTP2 == true) {
|
||||||
key: key,
|
key: key,
|
||||||
cert: cert,
|
cert: cert,
|
||||||
requireHostHeader: false,
|
requireHostHeader: false,
|
||||||
requestCert: configJSON.useClientCertificate,
|
requestCert: process.serverConfig.useClientCertificate,
|
||||||
rejectUnauthorized: configJSON.rejectUnauthorizedClientCertificates,
|
rejectUnauthorized:
|
||||||
ciphers: configJSON.cipherSuite,
|
process.serverConfig.rejectUnauthorizedClientCertificates,
|
||||||
ecdhCurve: configJSON.ecdhCurve,
|
ciphers: process.serverConfig.cipherSuite,
|
||||||
minVersion: configJSON.tlsMinVersion,
|
ecdhCurve: process.serverConfig.ecdhCurve,
|
||||||
maxVersion: configJSON.tlsMaxVersion,
|
minVersion: process.serverConfig.tlsMinVersion,
|
||||||
sigalgs: configJSON.signatureAlgorithms,
|
maxVersion: process.serverConfig.tlsMaxVersion,
|
||||||
|
sigalgs: process.serverConfig.signatureAlgorithms,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
@ -640,18 +694,37 @@ if (process.serverConfig.enableHTTP2 == true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load SNI contexts into HTTP server
|
// Load SNI contexts into HTTP server
|
||||||
if (secure) {
|
if (process.serverConfig.secure) {
|
||||||
try {
|
try {
|
||||||
sniCredentials.forEach(function (sniCredentialsSingle) {
|
sniCredentials.forEach(function (sniCredentialsSingle) {
|
||||||
server.addContext(sniCredentialsSingle.name, {
|
server.addContext(sniCredentialsSingle.name, {
|
||||||
cert: sniCredentialsSingle.cert,
|
cert: sniCredentialsSingle.cert,
|
||||||
key: sniCredentialsSingle.key
|
key: sniCredentialsSingle.key,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
var snMatches = sniCredentialsSingle.name.match(/^([^:[]*|\[[^]]*\]?)((?::.*)?)$/);
|
var snMatches = sniCredentialsSingle.name.match(
|
||||||
if (!snMatches[1][0].match(/^\.+$/)) snMatches[1][0] = snMatches[1][0].replace(/\.+$/, "");
|
/^([^:[]*|\[[^]]*\]?)((?::.*)?)$/,
|
||||||
server._contexts[server._contexts.length - 1][0] = new RegExp("^" + snMatches[1].replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.:]*") + ((snMatches[1][0] == "[" || snMatches[1].match(/^(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/)) ? "" : "\.?") + snMatches[2].replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.]*") + "$", "i");
|
);
|
||||||
} catch (ex) {
|
if (!snMatches[1][0].match(/^\.+$/))
|
||||||
|
snMatches[1][0] = snMatches[1][0].replace(/\.+$/, "");
|
||||||
|
server._contexts[server._contexts.length - 1][0] = new RegExp(
|
||||||
|
"^" +
|
||||||
|
snMatches[1]
|
||||||
|
.replace(/([.^$+?\-\\[\]{}])/g, "\\$1")
|
||||||
|
.replace(/\*/g, "[^.:]*") +
|
||||||
|
(snMatches[1][0] == "[" ||
|
||||||
|
snMatches[1].match(
|
||||||
|
/^(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/,
|
||||||
|
)
|
||||||
|
? ""
|
||||||
|
: ".?") +
|
||||||
|
snMatches[2]
|
||||||
|
.replace(/([.^$+?\-\\[\]{}])/g, "\\$1")
|
||||||
|
.replace(/\*/g, "[^.]*") +
|
||||||
|
"$",
|
||||||
|
"i",
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
// Can't replace regex, ignoring...
|
// Can't replace regex, ignoring...
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue