Files
Terminal-Website/server.js
2024-01-25 14:22:59 +01:00

56 lines
1.2 KiB
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;
}a
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);
break;
case "whoami":
commands.whoami(res);
break;
case "cd":
commands.cd(res, formatted_command);
break;
case "pwd":
commands.pwd(res);
break;
case "cat":
commands.cat(res, formatted_command )
break;
case "help":
commands.help(res);
}
})
app.get("/currentDir", (req, res)=>{
res.send(commands.getCurrentDir());
})
app.listen(port, () => {
console.log(`Epic Terminal App listening on port ${port}`)
})