12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import os
- from flask import Flask, request, render_template, jsonify
- app = Flask(__name__, static_folder='public', template_folder='views')
- app.secret = os.environ.get('SECRET')
- DREAMS = ['Dreams are ephemeral']
- @app.after_request
- def apply_kr_hello(response):
- """Adds some headers to all responses."""
-
-
- if 'MADE_BY' in os.environ:
- response.headers["X-Was-Here"] = os.environ.get('MADE_BY')
-
-
- response.headers["X-Powered-By"] = os.environ.get('POWERED_BY')
- return response
- @app.route('/')
- def homepage():
- """Displays the homepage."""
- return render_template('index.html')
-
- @app.route('/dreams', methods=['GET', 'POST'])
- def dreams():
- """Simple API endpoint for dreams.
- In memory, ephemeral, like real dreams.
- """
-
-
- if 'dream' in request.args:
- DREAMS.append(request.args['dream'])
-
-
- return jsonify(DREAMS)
- if __name__ == '__main__':
- app.run()
|