Skip to content

Commit 2d51f51

Browse files
committed
[python] Flask: fix bugs
1 parent eec1c7c commit 2d51f51

3 files changed

Lines changed: 13 additions & 30 deletions

File tree

frameworks/flask/app.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@
55
import gzip
66
import mimetypes
77

8-
9-
mimetypes.add_type('.woff2' , 'font/woff2')
10-
mimetypes.add_type('.webp' , 'image/webp')
11-
128
import psycopg_pool
139
import psycopg.rows
1410

15-
from flask import Flask, request, make_response, Response,
11+
from flask import Flask, request, make_response, Response
1612
from flask import send_from_directory, jsonify
1713

1814

19-
app = Flask(__name__)
15+
app = Flask(__name__, static_folder = None)
2016
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
2117

2218

@@ -61,7 +57,7 @@ def db_close():
6157
DATABASE_POOL = None
6258

6359
def db_setup():
64-
global DATABASE_POOL, DATABASE_URL, WRK_COUNT
60+
global DATABASE_POOL, DATABASE_URL, PG_POOL_MIN_SIZE, PG_POOL_MAX_SIZE, WRK_COUNT
6561
db_close()
6662
if not DATABASE_URL:
6763
return
@@ -86,21 +82,6 @@ def db_setup():
8682

8783
# -- flask features ----------------------------------------------------------
8884

89-
'''
90-
@app.after_request
91-
def add_server_header(response):
92-
response.headers['Server'] = 'Flask'
93-
return response
94-
95-
class CustomJSONEncoder(json.JSONEncoder):
96-
def default(self, obj):
97-
if isinstance(obj, datetime):
98-
return obj.isoformat()
99-
return super().default(obj)
100-
101-
app.json_encoder = CustomJSONEncoder
102-
'''
103-
10485
@app.after_request
10586
def compress_response(response):
10687
if response.status_code < 200 or response.status_code in (204, 304, 206):
@@ -146,9 +127,9 @@ def pipeline():
146127
@app.route('/baseline11', methods=['GET', 'POST'])
147128
def baseline11():
148129
total = 0
149-
for v in request.args.values():
130+
for val in request.args.values():
150131
try:
151-
total += int(v)
132+
total += int(val)
152133
except ValueError:
153134
pass
154135
if request.method == 'POST' and request.data:
@@ -184,7 +165,7 @@ def async_db_endpoint():
184165
try:
185166
min_val = request.args.get('min', type=float)
186167
max_val = request.args.get('max', type=float)
187-
limit = request.args.get('limit', type=float)
168+
limit = request.args.get('limit', type=int)
188169
with DATABASE_POOL.connection() as db_conn:
189170
rows = db_conn.execute(DATABASE_QUERY, (min_val, max_val, limit)).fetchall()
190171
items = [
@@ -219,7 +200,9 @@ def upload_endpoint():
219200
return str(size)
220201

221202

222-
@app.route('/static/<path:filename>')
223-
def static_endpoint(filename):
224-
return send_from_directory('/data/static', filename)
203+
mimetypes.add_type('.woff2', 'font/woff2')
204+
mimetypes.add_type('.webp', 'image/webp')
225205

206+
@app.route('/static/<path:filepath>')
207+
def static_endpoint(filepath):
208+
return send_from_directory('/data/static', filepath)

frameworks/flask/gunicorn_conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
_CPU_COUNT = int(multiprocessing.cpu_count())
88
_WRK_COUNT = min(len(os.sched_getaffinity(0)), 128)
9-
_WRK_COUNT = max(WRK_COUNT, 4)
9+
_WRK_COUNT = max(_WRK_COUNT, 4)
1010

1111

1212
bind = "0.0.0.0:8080"

frameworks/flask/gunicorn_conf_ssl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
_CPU_COUNT = int(multiprocessing.cpu_count())
88
_WRK_COUNT = min(len(os.sched_getaffinity(0)), 128)
9-
_WRK_COUNT = max(WRK_COUNT, 4)
9+
_WRK_COUNT = max(_WRK_COUNT, 4)
1010

1111

1212
bind = "0.0.0.0:8081"

0 commit comments

Comments
 (0)