34 lines
745 B
JavaScript
34 lines
745 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;
|
|
const formatted_command = String(raw_command).trim();
|
|
|
|
const currentDir = req.query.currentDir
|
|
|
|
console.log(`Executed Command: ${formatted_command}`);
|
|
|
|
if (formatted_command.startsWith("cd")){
|
|
commands.cd(req, res);
|
|
}
|
|
else {
|
|
res.json({"response": "invalid command"})
|
|
}
|
|
})
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Example app listening on port ${port}`)
|
|
}) |