summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2020-12-24 12:17:46 +0100
committerxengineering <mail2xengineering@protonmail.com>2020-12-24 12:17:46 +0100
commit65713a14a0596a3493ca60696121c69b1e872b8c (patch)
tree105011910f48fb045a8a9775c568354824b3b80b
parenta46322e7fdb8e83edc3e4dc6f254973e9f694156 (diff)
downloadweb-template-65713a14a0596a3493ca60696121c69b1e872b8c.tar
web-template-65713a14a0596a3493ca60696121c69b1e872b8c.tar.zst
web-template-65713a14a0596a3493ca60696121c69b1e872b8c.zip
Add dynamic Functionality
-rwxr-xr-xflask/main.py42
-rw-r--r--webroot/index.html3
-rw-r--r--webroot/js/example.js14
-rw-r--r--webroot/template.html28
4 files changed, 59 insertions, 28 deletions
diff --git a/flask/main.py b/flask/main.py
new file mode 100755
index 0000000..be270b1
--- /dev/null
+++ b/flask/main.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python3
+
+
+"""
+ web-template - A Template Project for dynamic Web Applications.
+
+ Copyright (C) 2020 xengineering
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+"""
+
+
+import waitress
+from flask import Flask, request, jsonify
+
+
+app = Flask(__name__)
+
+
+@app.route('/', methods=['POST'])
+def api():
+ data = request.get_json(force=True)
+ print(data)
+ return jsonify({"result":"ok"})
+
+
+if __name__ == '__main__':
+ waitress.serve(app, listen='*:8080') # production server / bind to port
+ #serve(app, unix_socket='/run/web-template/unix.sock') # production server / unix domain socket
+ #app.run() # debug server - NOT FOR PRODUCTION!
+
diff --git a/webroot/index.html b/webroot/index.html
index 59922a2..a406de7 100644
--- a/webroot/index.html
+++ b/webroot/index.html
@@ -20,8 +20,11 @@
<div class="xcontent">
<h1>Web Template</h1>
+ <button onclick="example_post()">Call JS Function</button>
</div>
+ <script src="js/example.js"></script>
+
</body>
</html>
diff --git a/webroot/js/example.js b/webroot/js/example.js
new file mode 100644
index 0000000..59cf1ee
--- /dev/null
+++ b/webroot/js/example.js
@@ -0,0 +1,14 @@
+
+function example_post() {
+
+ var data = {
+ "key":"value",
+ }
+ var json = JSON.stringify(data);
+
+ var xhr = new XMLHttpRequest();
+ xhr.open("POST", "api", true);
+ xhr.send(json);
+
+}
+
diff --git a/webroot/template.html b/webroot/template.html
deleted file mode 100644
index 59922a2..0000000
--- a/webroot/template.html
+++ /dev/null
@@ -1,28 +0,0 @@
-<!DOCTYPE html>
-
-<html>
-
- <head>
-
- <title>Web Template</title>
-
- <meta charset="utf-8"/>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <link rel="stylesheet" href="css/xengineering.css" type="text/css">
-
- </head>
-
- <body>
-
- <div class="xmenu">
- <a href="https://example.com">HOME</a>
- </div>
-
- <div class="xcontent">
- <h1>Web Template</h1>
- </div>
-
- </body>
-
-</html>
-