[backend] add basic files for deploying and extending backend operations
This commit is contained in:
28
backend/src/main.py
Normal file
28
backend/src/main.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from flask import Flask
|
||||
import psycopg2 as psql
|
||||
from os import environ as env
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
db_params = {
|
||||
'database': env.get('DB_NAME'),
|
||||
'user': env.get('DB_USER'),
|
||||
'password': env.get('DB_PASS'),
|
||||
'host': env.get('DB_HOST'),
|
||||
'port': int(env.get('DB_PORT'))
|
||||
}
|
||||
|
||||
db = psql.connect(**db_params)
|
||||
|
||||
@app.route("/")
|
||||
def test():
|
||||
c = db.cursor()
|
||||
try:
|
||||
c.execute('SELECT * FROM movies')
|
||||
except Exception:
|
||||
db.rollback()
|
||||
return "Failed to fetch table 'movies'"
|
||||
|
||||
res = c.fetchmany(10)
|
||||
c.close()
|
||||
return "<p>Hello, World! test data:<br>" + "<br>".join(str(i) for i in res) + "</p>"
|
||||
Reference in New Issue
Block a user