feat: scripts

This commit is contained in:
2025-04-05 16:57:26 +08:00
parent bd4fe63cdc
commit 3e996ffab3
62 changed files with 4905 additions and 0 deletions

35
scripts/server2.js Normal file
View File

@@ -0,0 +1,35 @@
#! /usr/bin/env runjs
var httpserver = require('component-httpserver-ex.js');
var main = () => {
if (($ARGS == null) || ($ARGS.length < 2)) {
println('server2.js - Run server2.');
println();
println('ERROR: NO arguments assigned!');
println('CMD: server2.js <port> <path>');
println(' port server port');
println(' path server path');
return;
}
var port = parseInt($ARGS[0]);
var path = $STR($ARGS[1]);
if (isNaN(port) || (port <= 0) || (port > 65535)) {
println('ERROR: port error: ' + port);
return;
}
var filePath = $$.file(path);
if (!filePath.exists() || !filePath.isDirectory()) {
println('ERROR: path not exists or not a directory: ' + path);
return;
}
httpserver.serveHTTP(port, (httpExchange) => {
return httpserver.handleFile(httpExchange, { handleDir: true, basePath: path }) || {
status: 404,
text: 'File not found!'
};
});
};
main();