As Quentin mentioned you can create a fastify server or express one, the below example is using fastify
https://glitch.com/edit/#!/kindly-bald-gong
Basically:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Execute Python Script</title>
<link rel="stylesheet" href="/style.css" />
</head>
<body>
<button onclick="executeScript()">Execute Python Script</button>
<script>
function executeScript() {
fetch('/execute-script')
.then(response => {
if (response.ok) {
console.log('Python script executed successfully.');
} else {
console.error('Failed to execute Python script.');
}
})
.catch(error => {
console.error('An error occurred while executing the Python script:', error);
});
}
</script>
</body>
</html>
fastify.get("/execute-script", function (request, reply) {
exec("python ./src/scripts/skript.py", (error, stdout, stderr) => {
if (error) {
console.error("Failed to execute Python script:", error);
reply.code(500).send("Failed to execute Python script");
} else {
console.log("Python script executed successfully");
reply.send("Python script executed successfully");
}
});
});