Skip to content

Commit

Permalink
project added
Browse files Browse the repository at this point in the history
  • Loading branch information
gavlenamdev committed Mar 22, 2022
1 parent 0402a78 commit 08bb055
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
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
6 changes: 6 additions & 0 deletions app.py
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)
14 changes: 14 additions & 0 deletions config.py
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
13 changes: 13 additions & 0 deletions flask_boilerplate/__init__.py
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.
12 changes: 12 additions & 0 deletions flask_boilerplate/views/api.py
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')
39 changes: 39 additions & 0 deletions flask_boilerplate/views/error_handler.py
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
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask
gunicorn
1 change: 1 addition & 0 deletions scripts/create_venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# generates gunicorn.service and nginx.conf file
5 changes: 5 additions & 0 deletions scripts/restart.sh
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
5 changes: 5 additions & 0 deletions scripts/start.sh
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
2 changes: 2 additions & 0 deletions scripts/status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sudo systemctl status nginx
sudo systemctl status gunicorn
5 changes: 5 additions & 0 deletions scripts/stop.sh
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

0 comments on commit 08bb055

Please sign in to comment.