Guest User

Untitled

a guest
Mar 22nd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. # file app.py
  2.  
  3. import os
  4. from flask import Flask, render_template
  5. from .search_blueprint import search_blueprint
  6.  
  7. app = Flask(__name__)
  8. app.register_blueprint(search_blueprint, url_prefix='/search')
  9.  
  10. @app.route('/')
  11. def index():
  12. return render_template('index.html')
  13.  
  14. if __name__ == '__main__':
  15. app.run(use_reloader=True, port=5000, threaded=True)
  16.  
  17. # file search_blueprint.py
  18.  
  19. from flask import Blueprint, send_from_directory
  20. import os
  21.  
  22. build_dir = os.path.abspath('./app/static/build')
  23. search_blueprint = Blueprint('search', __name__, static_folder=build_dir)
  24.  
  25. # Serve React App
  26. @search_blueprint.route('/', defaults={'path': ''})
  27. @search_blueprint.route('/<path:path>')
  28. def serve(path):
  29. if(path == ""):
  30. return send_from_directory(build_dir, 'index.html')
  31. else:
  32. if(os.path.exists(os.path.join(build_dir, path))):
  33. return send_from_directory(build_dir, path)
  34. else:
  35. return send_from_directory(build_dir, 'index.html')
  36.  
  37. app
  38. ├───static
  39. │ └───build
  40. ├───templates
  41. │ └───index.html
  42. ├───app.py
  43. └───search_blueprint.py
Add Comment
Please, Sign In to add comment