Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # file app.py
- import os
- from flask import Flask, render_template
- from .search_blueprint import search_blueprint
- app = Flask(__name__)
- app.register_blueprint(search_blueprint, url_prefix='/search')
- @app.route('/')
- def index():
- return render_template('index.html')
- if __name__ == '__main__':
- app.run(use_reloader=True, port=5000, threaded=True)
- # file search_blueprint.py
- from flask import Blueprint, send_from_directory
- import os
- build_dir = os.path.abspath('./app/static/build')
- search_blueprint = Blueprint('search', __name__, static_folder=build_dir)
- # Serve React App
- @search_blueprint.route('/', defaults={'path': ''})
- @search_blueprint.route('/<path:path>')
- def serve(path):
- if(path == ""):
- return send_from_directory(build_dir, 'index.html')
- else:
- if(os.path.exists(os.path.join(build_dir, path))):
- return send_from_directory(build_dir, path)
- else:
- return send_from_directory(build_dir, 'index.html')
- app
- ├───static
- │ └───build
- ├───templates
- │ └───index.html
- ├───app.py
- └───search_blueprint.py
Add Comment
Please, Sign In to add comment