WIP: Article checker with svelte

This commit is contained in:
2022-08-31 12:09:21 +02:00
parent 0c7ff29068
commit e1a8dabd2c
23 changed files with 2656 additions and 7 deletions

View File

@@ -0,0 +1,10 @@
# Svelte.js + Flask
A super simple example of using Flask to serve a Svelte app and use it as a backend server.
Run the following for development:
- `python server.py` to start the Flask server.
- `cd client; npm install; npm run autobuild` to automatically build and reload the Svelte frontend when it's changed.
This example just queries the Flask server for a random number.

37
news_check/server/main.py Normal file
View File

@@ -0,0 +1,37 @@
from crypt import methods
import json
from flask import Flask, send_from_directory, jsonify
import random
app = Flask(__name__)
###############################################################################
# SVELTE BACKEND. Always send index.html and the requested js-files. (compiled by npm)
@app.route("/") #index.html
def base():
return send_from_directory('../client/public', 'index.html')
@app.route("/<path:path>") #js-files
def home(path):
return send_from_directory('../client/public', path)
###############################################################################
# API for news_check.
@app.route("/api/article/<int:id>/get")
def get_article(id):
res = {"value": id}
return jsonify(res)
@app.route("/api/article/<int:id>/set", methods=['POST'])
def set_article(id):
return str(random.randint(0, 100))
if __name__ == "__main__":
app.run(debug=True)

3
news_check/server/package-lock.json generated Normal file
View File

@@ -0,0 +1,3 @@
{
"lockfileVersion": 1
}