Commit a4f8caa0 authored by Waqas Riaz's avatar Waqas Riaz

added flask backend

parent 44646eb0
from flask import Flask
import json
import logging
import mariadb
from os import environ
config = {
'host': environ.get('DB_HOST'),
'port': int(environ.get('DB_PORT')),
'user': environ.get('DB_USER'),
'password': environ.get('DB_PASS'),
'database': environ.get('DB_NAME')
}
app = Flask(__name__)
gunicorn_error_logger = logging.getLogger('gunicorn.error')
app.logger.handlers.extend(gunicorn_error_logger.handlers)
app.logger.setLevel(logging.INFO)
# queries the Menu table and returns the output in json format.
@app.route('/', methods=['GET'])
def index():
#connection for MariaDB
conn = mariadb.connect(**config)
# conn = mysql.connector.connect(**config)
# create a connection cursor
cur = conn.cursor()
# execute a SQL statement
cur.execute("select * from Employees")
# serialize results into JSON
row_headers=[x[0] for x in cur.description]
rv = cur.fetchall()
json_data=[]
for result in rv:
json_data.append(dict(zip(row_headers,result)))
# return the results!
return json.dumps(json_data)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000, debug=True, threaded=True)
\ No newline at end of file
# syntax=docker/dockerfile:1
FROM ubuntu:focal
WORKDIR /tukkar-app
RUN apt-get update && apt-get install -y libmariadb3 libmariadb-dev python3-pip
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
EXPOSE 5000
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
\ No newline at end of file
Flask==2.0.3
gunicorn==20.1.0
mariadb
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment