55import gzip
66import mimetypes
77
8-
9- mimetypes .add_type ('.woff2' , 'font/woff2' )
10- mimetypes .add_type ('.webp' , 'image/webp' )
11-
128import psycopg_pool
139import psycopg .rows
1410
15- from flask import Flask , request , make_response , Response ,
11+ from flask import Flask , request , make_response , Response
1612from flask import send_from_directory , jsonify
1713
1814
19- app = Flask (__name__ )
15+ app = Flask (__name__ , static_folder = None )
2016app .config ['JSONIFY_PRETTYPRINT_REGULAR' ] = False
2117
2218
@@ -61,7 +57,7 @@ def db_close():
6157 DATABASE_POOL = None
6258
6359def 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
10586def 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' ])
147128def 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 )
0 commit comments