init2 server
This commit is contained in:
11
server.py
11
server.py
@@ -1,13 +1,13 @@
|
|||||||
from flask import Flask, request, jsonify, render_template
|
from flask import render_template, Flask, request, jsonify
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__, static_url_path='/unsecure/static')
|
||||||
pending_command = None
|
pending_command = None
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/unsecure')
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html') # Lädt templates/index.html
|
return render_template('index.html') # Lädt templates/index.html
|
||||||
|
|
||||||
@app.route('/send')
|
@app.route('/unsecure/send')
|
||||||
def send_command():
|
def send_command():
|
||||||
global pending_command
|
global pending_command
|
||||||
befehl = request.args.get('befehl')
|
befehl = request.args.get('befehl')
|
||||||
@@ -16,7 +16,7 @@ def send_command():
|
|||||||
return f"Befehl '{befehl}' gespeichert."
|
return f"Befehl '{befehl}' gespeichert."
|
||||||
return "Kein Befehl angegeben.", 400
|
return "Kein Befehl angegeben.", 400
|
||||||
|
|
||||||
@app.route('/fetch')
|
@app.route('/unsecure/fetch')
|
||||||
def fetch_command():
|
def fetch_command():
|
||||||
global pending_command
|
global pending_command
|
||||||
if pending_command:
|
if pending_command:
|
||||||
@@ -24,6 +24,5 @@ def fetch_command():
|
|||||||
pending_command = None
|
pending_command = None
|
||||||
return jsonify({'befehl': cmd})
|
return jsonify({'befehl': cmd})
|
||||||
return jsonify({'befehl': None})
|
return jsonify({'befehl': None})
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=3060)
|
app.run(host='0.0.0.0', port=3060)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ document.getElementById('befehlForm').addEventListener('submit', function(event)
|
|||||||
|
|
||||||
const befehl = document.getElementById('befehl').value;
|
const befehl = document.getElementById('befehl').value;
|
||||||
|
|
||||||
fetch(`/send?befehl=${encodeURIComponent(befehl)}`)
|
fetch(`/unsecure/send?befehl=${encodeURIComponent(befehl)}`)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(text => {
|
.then(text => {
|
||||||
document.getElementById('status').textContent = text;
|
document.getElementById('status').textContent = text;
|
||||||
@@ -11,4 +11,4 @@ document.getElementById('befehlForm').addEventListener('submit', function(event)
|
|||||||
.catch(err => {
|
.catch(err => {
|
||||||
document.getElementById('status').textContent = 'Fehler beim Senden.';
|
document.getElementById('status').textContent = 'Fehler beim Senden.';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -18,4 +18,4 @@
|
|||||||
|
|
||||||
<script src="{{ url_for('static', filename='script.js') }}"></script>
|
<script src="{{ url_for('static', filename='script.js') }}"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user