1234567891011121314151617181920212223242526272829 |
- import os
- from flask import send_from_directory, jsonify, Blueprint, current_app
- from flask_cors import CORS, cross_origin
-
-
- articles_api_bp = Blueprint(
- "articles", __name__, template_folder="templates")
-
- cors = CORS(articles_api_bp, resources={r"/articles": {"origins": "http://localhost:5500"}})
-
-
- @articles_api_bp.route("/<path:article>")
- @cross_origin(origin="localhost", headers=["Content-Type", "Authorization"])
- def send_text_file(article):
- return send_from_directory(directory="articles_files", path=article)
-
-
- @articles_api_bp.route('/')
- @cross_origin(origin="localhost", headers=["Content-Type", "Authorization"])
- def index():
- # List files in articles directory
- files = list()
- for filename in os.listdir(os.path.join(
- current_app.root_path, "articles_files")):
- path = os.path.join(os.path.join(
- current_app.root_path, "articles_files"), filename)
- if os.path.isfile(path):
- files.append(filename)
- return jsonify(files)
|