fix: refactor networking scripts for improved robustness and clarity

This commit is contained in:
Timothy Hofland
2026-03-16 08:42:26 +01:00
parent 855339ef42
commit 4ad82a1a66
4 changed files with 167 additions and 83 deletions

View File

@ -9,6 +9,8 @@ const fs = require('fs');
const path = require('path');
const multer = require('multer');
const scriptsDir = path.join(__dirname, '../scripts');
const app = express();
app.use(express.json());
app.use(express.static(path.join(__dirname, '../frontend/dist')));
@ -120,14 +122,14 @@ app.post('/media/assign', (req, res) => {
// Networking API
app.post('/network/ap', (req, res) => {
exec('bash scripts/switch-to-ap.sh', (err, stdout) => {
exec(`bash "${path.join(scriptsDir, 'switch-to-ap.sh')}"`, (err, stdout) => {
if (err) return res.status(500).json({ error: err.message });
res.json({ status: 'switching to ap', output: stdout });
});
});
app.post('/network/client', (req, res) => {
exec('bash scripts/switch-to-client.sh', (err, stdout) => {
exec(`bash "${path.join(scriptsDir, 'switch-to-client.sh')}"`, (err, stdout) => {
if (err) return res.status(500).json({ error: err.message });
res.json({ status: 'switching to client', output: stdout });
});