Add args for production

This commit is contained in:
Wildan M 2021-09-20 20:11:57 +07:00
commit ca79e88b46
3 changed files with 11 additions and 9 deletions

6
app.js
View file

@ -4,14 +4,16 @@ const https = require("https");
const app = require("./index.js");
const listener = require("./src/client.js");
const { SniPrepare, SniListener } = require("./src/sni.js");
const port80 = (process.argv.length >= 2 ? parseInt(process.argv[2]) : 0) || 80;
const port443 = (process.argv.length >= 3 ? parseInt(process.argv[3]) : 0) || 443;
const main = async () => {
await SniPrepare();
const httpsServer = https.createServer({
SNICallback: SniListener,
}, listener);
httpsServer.listen(443);
app.listen(80);
httpsServer.listen(port443);
app.listen(port80);
};
main().catch((err) => {

View file

@ -23,9 +23,9 @@ const PUBLIC_KEY_TYPE = 'spki'
* @param {crypto.KeyObject} privateKey
* @param {String} [passphrase]
*
* @return {String}
*/
const exportPrivateKey = (privateKey, passphrase) => {
/** @type {crypto.KeyExportOptions<'pem'>} */
const privateKeyOpts = {
type: PRIVATE_KEY_TYPE,
format: PRIVATE_KEY_FORMAT
@ -41,10 +41,9 @@ const exportPrivateKey = (privateKey, passphrase) => {
/**
* @param {crypto.KeyObject} publicKey
*
* @return {String}
*/
const exportPublicKey = publicKey => {
/** @type {crypto.KeyExportOptions<'pem'>} */
return publicKey.export({
type: PUBLIC_KEY_TYPE,
format: PUBLIC_KEY_FORMAT
@ -55,9 +54,10 @@ const exportPublicKey = publicKey => {
* @param {String} privateKeyData
* @param {String} [passphrase]
*
* @return {String}
* @return {crypto.KeyObject}
*/
const importPrivateKey = (privateKeyData, passphrase) => {
/** @type {crypto.KeyExportOptions<'pem'>} */
const privateKeyOpts = {
key: privateKeyData,
format: PRIVATE_KEY_FORMAT,
@ -93,8 +93,8 @@ const importPublicKey = publicKeyData => {
}
/**
* @param {String} dirname
* @param {(crypto.KeyObject|String)} key
* @param {String} filename
* @param {crypto.KeyObject|string} key
* @param {String} [passphrase]
*
* @return {Promise}

View file

@ -1,6 +1,6 @@
const https = require('https')
const request = (url, { data = '', ...options } = {}, cb) => {
const request = (/** @type {string | import("url").URL} */ url, /** @type {https.RequestOptions&{data?: string}} */ { data = '', ...options } = {}, /** @type {() => any} */ cb) => {
return new Promise((resolve, reject) => {
try {
url = new URL(url)