41 lines
961 B
JavaScript
41 lines
961 B
JavaScript
const express = require('express')
|
|
const app = express()
|
|
const port = 3000
|
|
|
|
const commands = require("./commands/commands")
|
|
|
|
app.use(express.static("httpdocs/public"))
|
|
|
|
const documentRoot = `${__dirname}/httpdocs`
|
|
|
|
|
|
app.get('/', (req, res) => {
|
|
res.sendFile(documentRoot+"/index.html")
|
|
})
|
|
|
|
app.get("/execute", (req, res)=> {
|
|
const raw_command = req.query.command;
|
|
if (raw_command == ""){
|
|
commands.customTextResponse(res, "");
|
|
return;
|
|
}
|
|
|
|
const formatted_command = raw_command.trim();
|
|
const command = formatted_command.split(" ")[0]
|
|
|
|
switch(command){
|
|
default:
|
|
commands.customTextResponse(res, "Command '"+command+"' not found, please try again later, or type 'help' for the list of available commands");
|
|
break;
|
|
case "ls":
|
|
commands.ls(res);
|
|
}
|
|
})
|
|
|
|
app.get("/currentDir", (req, res)=>{
|
|
res.send(commands.getCurrentDir());
|
|
})
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Epic Terminal App listening on port ${port}`)
|
|
}) |