Last active
February 9, 2022 16:58
-
-
Save lost-theory/d6beaeb7ae5ead166227 to your computer and use it in GitHub Desktop.
Revisions
-
lost-theory revised this gist
Feb 25, 2015 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,6 @@ from flask import Flask, Blueprint, g api = Blueprint('api', __name__) class Server(object): -
lost-theory revised this gist
Feb 25, 2015 . 4 changed files with 45 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ import os from flask import Flask, Blueprint, g app = Flask(__name__) api = Blueprint('api', __name__) class Server(object): def __init__(self, data): self.data = data @api.route("/api_method", methods=['GET', 'POST']) def api_method(): return g.server.data def make_app(): ''' Application factory: http://flask.pocoo.org/docs/0.10/patterns/appfactories/ ''' app = Flask(__name__) app.register_blueprint(api) with open(os.environ['SERVER_FILE']) as f: server = Server(f.read()) @app.before_request def add_server_to_globals(): g.server = server return app if __name__ == '__main__': app = make_app() app.config['DEBUG'] = True app.run(use_debugger=True, use_reloader=True) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ from app_factory import make_app app = make_app() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ def __init__(self, data): def api_method(): return g.server.data @app.before_request def add_server_to_globals(): with open(os.environ['SERVER_FILE']) as f: g.server = Server(f.read()) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,16 @@ $ SERVER_FILE=app.py bin/gunicorn app_simple:app [2015-02-24 10:10:20 -0800] [3217] [INFO] Starting gunicorn 19.2.1 [2015-02-24 10:10:20 -0800] [3217] [INFO] Listening at: http://127.0.0.1:8000 (3217) [2015-02-24 10:10:20 -0800] [3217] [INFO] Using worker: sync [2015-02-24 10:10:20 -0800] [3220] [INFO] Booting worker with pid: 3220 ... OR if you use the application factory: $ SERVER_FILE=app.py bin/gunicorn app_gunicorn:app [2015-02-25 09:52:29 -0800] [5613] [INFO] Starting gunicorn 19.2.1 ... $ curl http://127.0.0.1:8000/api_method import os -
lost-theory created this gist
Feb 24, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ import os from flask import Flask, g app = Flask(__name__) class Server(object): def __init__(self, data): self.data = data @app.route("/api_method", methods=['GET', 'POST']) def api_method(): return g.server.data @app.before_first_request def add_server_to_globals(): with open(os.environ['SERVER_FILE']) as f: g.server = Server(f.read()) if __name__ == '__main__': app.run() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ $ SERVER_FILE=app.py bin/gunicorn app:app [2015-02-24 10:10:20 -0800] [3217] [INFO] Starting gunicorn 19.2.1 [2015-02-24 10:10:20 -0800] [3217] [INFO] Listening at: http://127.0.0.1:8000 (3217) [2015-02-24 10:10:20 -0800] [3217] [INFO] Using worker: sync [2015-02-24 10:10:20 -0800] [3220] [INFO] Booting worker with pid: 3220 ... $ curl http://127.0.0.1:8000/api_method import os from flask import Flask, g app = Flask(__name__) ...