WIP: Article checker with svelte
This commit is contained in:
10
news_check/server/README.md
Normal file
10
news_check/server/README.md
Normal 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
37
news_check/server/main.py
Normal 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
3
news_check/server/package-lock.json
generated
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"lockfileVersion": 1
|
||||
}
|
Reference in New Issue
Block a user