From 2c5800b9450813a93aa881f6084ea9743d90474e Mon Sep 17 00:00:00 2001 From: Amos Jones Date: Mon, 13 Nov 2023 10:32:56 -0700 Subject: [PATCH] this solves issues 2 & 3 --- index.js => app.js | 12 ++++++++++-- static/index.html | 17 +++++++++++++++++ static/index.js | 7 +++++++ 3 files changed, 34 insertions(+), 2 deletions(-) rename index.js => app.js (71%) mode change 100755 => 100644 create mode 100644 static/index.html create mode 100755 static/index.js diff --git a/index.js b/app.js old mode 100755 new mode 100644 similarity index 71% rename from index.js rename to app.js index a1d3964..b866e3a --- a/index.js +++ b/app.js @@ -2,6 +2,7 @@ const axios = require('axios'); const express = require('express') const app = express() const port = 3000 +const path = require('path'); async function resetvm(vmid){ try { @@ -18,7 +19,14 @@ async function resetvm(vmid){ } } -app.get('/:id', async (req, res) => { + +app.use('/static', express.static(path.join(__dirname, 'static'))); + +app.get('/', function(req, res) { + res.sendFile(path.join(__dirname, '/static/index.html')); +}); + +app.post('/:id', async (req, res) => { let apiCall = await resetvm(req.params.id) if(apiCall){ res.send(`the vm ${req.params.id} has been reset`) @@ -28,5 +36,5 @@ app.get('/:id', async (req, res) => { }) app.listen(port, () => { - console.log(`Example app listening on port ${port}`) + console.log(`App listening on port ${port}`) }) \ No newline at end of file diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..2086e3f --- /dev/null +++ b/static/index.html @@ -0,0 +1,17 @@ + + + + Page Title + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/static/index.js b/static/index.js new file mode 100755 index 0000000..3d12805 --- /dev/null +++ b/static/index.js @@ -0,0 +1,7 @@ +$(document).ready(function(){ + $('#reset').on('click', function(){ + $.post("http://localhost:3000/110", function( data ){ + $( "#result" ).html( data ); + }); + }); +}); \ No newline at end of file