-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0402a78
commit 08bb055
Showing
13 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Flask Project Boilerplate | ||
|
||
|
||
#### deployment using gunicorn, nginx | ||
|
||
|
||
|
||
#### TODOs | ||
1. [ ] read configs from .env | ||
2. [ ] docker |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from flask_boilerplate import create_app | ||
|
||
app = create_app() | ||
|
||
if __name__ == "__main__": | ||
app.run(debug=True, threaded=True) |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Config: | ||
DEBUG = True | ||
|
||
|
||
class Development(Config): | ||
pass | ||
|
||
|
||
class Testing(Config): | ||
pass | ||
|
||
|
||
class Production(Config): | ||
DEBUG = False |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from flask import Flask | ||
|
||
|
||
def create_app(): | ||
app = Flask(__name__) | ||
app.config.from_pyfile('../config.py') | ||
|
||
from .views.api import api | ||
from .views.error_handler import error_handler | ||
app.register_blueprint(api) | ||
app.register_blueprint(error_handler) | ||
|
||
return app |
Empty file.
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import json | ||
import logging | ||
|
||
from flask import Response, Blueprint | ||
|
||
api = Blueprint("api", import_name=__name__) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@api.route("/test") | ||
def test(): | ||
return Response(json.dumps({"message": "success"}), status=200, mimetype='application/json') |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import json | ||
|
||
from flask import Blueprint | ||
from flask import Response | ||
|
||
error_handler = Blueprint('error_handler', import_name=__name__) | ||
|
||
|
||
@error_handler.errorhandler(404) | ||
def page_not_found(e): | ||
return Response( | ||
json.dumps({ | ||
'status': False, | ||
'message': "page not found", | ||
}), | ||
mimetype='application/json' | ||
), 404 | ||
|
||
|
||
@error_handler.errorhandler(500) | ||
def internal_server_error(e): | ||
return Response( | ||
json.dumps({ | ||
'status': False, | ||
'message': "internal server error", | ||
}), | ||
mimetype='application/json' | ||
), 500 | ||
|
||
|
||
@error_handler.errorhandler(429) | ||
def too_many_requests_error(e): | ||
return Response( | ||
json.dumps({ | ||
'status': False, | ||
'message': "Sorry, you are making too many requests to our servers", | ||
}), | ||
mimetype='application/json' | ||
), 429 |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
flask | ||
gunicorn |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# generates gunicorn.service and nginx.conf file |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sudo systemctl restart nginx | ||
sudo systemctl restart gunicorn | ||
|
||
sudo systemctl status nginx | ||
sudo systemctl status gunicorn |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sudo systemctl start nginx | ||
sudo systemctl start gunicorn | ||
|
||
sudo systemctl status nginx | ||
sudo systemctl status gunicorn |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
sudo systemctl status nginx | ||
sudo systemctl status gunicorn |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sudo systemctl stop nginx | ||
sudo systemctl stop gunicorn | ||
|
||
sudo systemctl status nginx | ||
sudo systemctl status gunicorn |