-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
48 lines (32 loc) · 1.04 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import psycopg2
import os
from flask import Flask, jsonify
from cfenv import AppEnv
from psycopg2.extras import RealDictCursor
from flask_cors import CORS
origin = os.getenv("ORIGIN")
port = int(os.getenv("PORT", 8080))
app = Flask(__name__)
CORS(app, origins=origin)
app_env = AppEnv()
aws_rds = app_env.get_service(name="example-website-api-database")
connection = psycopg2.connect(
host=aws_rds.credentials.get("host"),
user=aws_rds.credentials.get("username"),
password=aws_rds.credentials.get("password"),
database=aws_rds.credentials.get("name"),
port=aws_rds.credentials.get("port"),
)
@app.route("/", methods=["GET"])
def hello():
return "There is a table right behind this door!"
@app.route("/get_table", methods=["GET"])
def get_table():
cursor = connection.cursor(cursor_factory=RealDictCursor)
query = "SELECT * FROM fdic_banks LIMIT 15"
cursor.execute(query)
rows = cursor.fetchall()
cursor.close()
return jsonify(rows)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=port)