-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
19,695 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
const { program } = require('commander'); | ||
const open = require('open'); | ||
const readline = require('readline'); | ||
const net = require('net'); | ||
const Socket = net.Socket; | ||
const serverModule = require('./modules/server'); | ||
const settingsModule = require('./modules/settings'); | ||
const logsModule = require('./modules/logs'); | ||
|
||
|
||
process.on('SIGINT', async function() { | ||
serverModule.stopAll(); | ||
}); | ||
|
||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}); | ||
|
||
async function isPortTaken(port) { | ||
return new Promise((resolve) => { | ||
const socket = new Socket(); | ||
socket.on("timeout", () => { | ||
resolve(false); | ||
socket.destroy(); | ||
}); | ||
socket.on("connect", () => { | ||
resolve(true); | ||
}); | ||
socket.on("error", error => { | ||
if (error.code !== "ECONNREFUSED") resolve(true); | ||
else resolve(false); | ||
}); | ||
socket.connect(port, "0.0.0.0"); | ||
}); | ||
} | ||
|
||
async function findAvailablePort(startPort) { | ||
let port = startPort; | ||
let maxPort = startPort + 100; | ||
while (await isPortTaken(port)) { | ||
if (port >= maxPort) { | ||
throw new Error('No available ports found'); | ||
} | ||
port++; | ||
} | ||
return port; | ||
} | ||
|
||
const originalLog = console.log; | ||
|
||
console.log = function (...args) { | ||
originalLog.apply(console, args); | ||
rl.prompt(); | ||
}; | ||
|
||
program | ||
.option('-p, --port <port>', 'Set server port', parseInt) | ||
.option('-d, --dir <dir>', 'Set server dir', String) | ||
.option('-r, --run', 'Run the server', false) | ||
.parse(process.argv); | ||
(async () => { | ||
await settingsModule.init(); | ||
await settingsModule.read(); | ||
const port = await findAvailablePort(3000); | ||
const subPort = program.opts().port || 8080; | ||
const autoServer = program.opts().run || false; | ||
const pathServer = program.opts().dir || settingsModule.getObjects().path; | ||
await serverModule.startMain(port, pathServer, autoServer, subPort); | ||
|
||
|
||
if (settingsModule.getObjects().app.auto_web) { | ||
await open(`http://localhost:${port}`); | ||
} | ||
|
||
let exit = false; | ||
readline.emitKeypressEvents(process.stdin); | ||
process.stdin.on('keypress', (ch, key) => { | ||
if (key && key.name === 'escape') { | ||
console.log('Close app? (y)'); | ||
exit = true | ||
rl.prompt(); | ||
} else if (key && key.name === 'y' && exit) { | ||
console.log('\nExiting application...'); | ||
rl.close(); | ||
} else { | ||
exit = false | ||
} | ||
}); | ||
process.stdin.setRawMode(true); | ||
|
||
rl.on('line', async(input) => { | ||
if (input.trim() === 'open') { | ||
await open(`http://localhost:${port}`); | ||
} else if (input.trim() === 'exit') { | ||
console.log('Exiting application...'); | ||
} else if (input.trim() === 'stop') { | ||
await serverModule.stop(); | ||
} else if (input.trim() === 'run') { | ||
await serverModule.run(); | ||
} else if (input.trim() === 'help' || input.trim() === '-h') { | ||
const help = | ||
'exit - Close application\n' + | ||
'run - Start server\n' + | ||
'stop - Stop server'; | ||
console.log(help); | ||
} else { | ||
console.log('Unknown command. To get available commands -h'); | ||
} | ||
rl.prompt(); | ||
}); | ||
rl.prompt(); | ||
|
||
rl.on('close', async() => { | ||
console.log('Application closed.'); | ||
await logsModule.write('Application closed.') | ||
process.exit(0); | ||
}); | ||
})(); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIEBDCCAuygAwIBAgIEOvfXxTANBgkqhkiG9w0BAQsFADCBmjELMAkGA1UEBhMC | ||
VUExCjAIBgNVBAMMASoxHDAaBgNVBAgME0NoZXJuaWhpdnNrYSB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/sDZ3wVdqV/novHe2wKVf7e4tJQR6NZ | ||
ytGCoHOYttoA6p0QfZz6K+3ASzKHNBDz/0lyPncHhUt7zd8aC5zBp3nDZsl8SVPq | ||
k/2NetV+sewHyGRYGqKTVFhUkaCg7RuXdS6ueaHkWUxLo+feeDRZnN+qlh79EbgL | ||
Nli9Atj4tof/mcvce3g4x+hCoiIeWuA4Kt94LR1YpC8MnK1Gg/S/HwnwL5jCTOxS | ||
KKFUepRtTC6Utjah/KptgbluVyo2r8cx | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCzmM2ByX3YmDIS | ||
AajNJvR8G+ULpqHOOZj2fxfaZpvioeAMSsWypBqCSPwHWfph+sB257MNdx5fcgmT | ||
C58En9acOPqiAdgZoDwlZdHvrb8BRTiKhfGCDUfF8jLd2kmgR177vPkP98wn/66Z | ||
L9zLn7aDJcb8OlQJ73tMqGDqdEZFTM/y1EeTw61r32k1gQgtq2NBn1PsdgjSMorY | ||
YS03jUwVwXUKCwphLY25JcfdGZ+UicA7NMO1SdnIjQvjAZB0YNvS5+1/O9xJjSA3 | ||
jd8XnHTNM3WbqdFO2OhcSOh9H7eWecAGCvPxn0NWqFOGsFw+m7bNEmvgH+l/n07i | ||
LfIh4gR9AgMBAAECggEAUHJlu3kx8c9avk4X+q00XlNwaaOeXu3V4rRTTvUfZojz | ||
/w2PONHhPfLLUc+wJCtaAukOfz2YUVCXkVJnTH78dsXfHqqMzg3EY0wUmbPOFxeW | ||
mBYfdA3W1IgE2PNqf2z40vJ27fwlatVQtDWIRX2pF13YoCrQchLfvBrALsUepPNe | ||
+l9Xih2/n7vmsqNrz+ZjloKfXprQ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eW | ||
-----END PRIVATE KEY----- |
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.