forked from svrjs/svrjs
Add commands
This commit is contained in:
parent
a241af753e
commit
98c36d2b64
1 changed files with 45 additions and 0 deletions
45
src/index.js
45
src/index.js
|
@ -465,6 +465,7 @@ if (!disableMods) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Middleware
|
||||||
let middleware = [
|
let middleware = [
|
||||||
require("./middleware/urlSanitizer.js"),
|
require("./middleware/urlSanitizer.js"),
|
||||||
require("./middleware/redirects.js"),
|
require("./middleware/redirects.js"),
|
||||||
|
@ -481,6 +482,50 @@ let middleware = [
|
||||||
require("./middleware/staticFileServingAndDirectoryListings.js"),
|
require("./middleware/staticFileServingAndDirectoryListings.js"),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// TODO: close, open, stop, restart commands
|
||||||
|
// Base commands
|
||||||
|
let commands = {
|
||||||
|
help: (args, log) => {
|
||||||
|
log("Server commands:\n" + Object.keys(commands).join(" "));
|
||||||
|
},
|
||||||
|
mods: function (args, log) {
|
||||||
|
log("Mods:");
|
||||||
|
for (let i = 0; i < modInfos.length; i++) {
|
||||||
|
log(
|
||||||
|
(i + 1).toString() +
|
||||||
|
". " +
|
||||||
|
modInfos[i].name +
|
||||||
|
" " +
|
||||||
|
modInfos[i].version,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (modInfos.length == 0) {
|
||||||
|
log("No mods installed.");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
clear: function (args, log) {
|
||||||
|
console.clear();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Load commands from middleware
|
||||||
|
middleware.forEach((middlewareO) => {
|
||||||
|
if (middlewareO.commands) {
|
||||||
|
Object.keys(middlewareO.commands).forEach((command) => {
|
||||||
|
if (commands[command]) {
|
||||||
|
commands[command] = (args, log) => {
|
||||||
|
middlewareO.commands(args, log, commands[command]);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
commands[command] = (args, log) => {
|
||||||
|
middlewareO.commands(args, log, () => {});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// HTTP server handlers
|
||||||
const requestHandler = require("./handlers/requestHandler.js")(
|
const requestHandler = require("./handlers/requestHandler.js")(
|
||||||
serverconsole,
|
serverconsole,
|
||||||
middleware,
|
middleware,
|
||||||
|
|
Reference in a new issue