feat: scripts
This commit is contained in:
35
scripts/server2.js
Normal file
35
scripts/server2.js
Normal 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();
|
||||
Reference in New Issue
Block a user