1234567891011121314151617181920212223242526272829303132 |
- import os
- from flask import Flask, send_from_directory, jsonify
- from flask_cors import CORS, cross_origin
-
-
- app = Flask(__name__, static_url_path='')
- app.config["SECRET_KEY"] = "f82abccd93a28b6cdda4525c9afa7a30"
- app.config["CORS_HEADERS"] = "Content-Type"
-
- cors = CORS(app, resources={r"/articles": {"origins": "http://localhost:5500"}})
-
-
- @app.route("/articles/<path:article>")
- @cross_origin(origin="localhost", headers=["Content-Type", "Authorization"])
- def send_text_file(article):
- return send_from_directory(directory="articles", path=article)
-
-
- @app.route("/articles")
- @cross_origin(origin="localhost", headers=["Content-Type", "Authorization"])
- def list_files():
- files = list()
- for filename in os.listdir("articles"):
- path = os.path.join("articles", filename)
- if os.path.isfile(path):
- files.append(filename)
- return jsonify(files)
-
-
- if __name__ == "__main__":
- app.run()
|