Skip to content

Commit

Permalink
Merge pull request #328 from hackforla/323_BACK_GZip
Browse files Browse the repository at this point in the history
Adds server side gzip compression
  • Loading branch information
sellnat77 authored Mar 1, 2020
2 parents 3fac0a1 + ca60a40 commit 8ae7602
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ requests-async==0.5.0
rfc3986==1.3.2
sanic==19.9.0
Sanic-Cors==0.10.0.post3
sanic-gzip==0.3.0
Sanic-Plugins-Framework==0.9.2
six==1.14.0
sodapy==2.0.0
Expand Down
11 changes: 11 additions & 0 deletions server/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from sanic import Sanic
from sanic.response import json
from sanic_cors import CORS
from sanic_gzip import Compress
from configparser import ConfigParser
from threading import Timer
from datetime import datetime
Expand All @@ -16,6 +17,7 @@

app = Sanic(__name__)
CORS(app)
compress = Compress()


def configure_app():
Expand All @@ -32,11 +34,13 @@ def configure_app():


@app.route('/')
@compress.compress()
async def index(request):
return json('You hit the index')


@app.route('/timetoclose')
@compress.compress()
async def timetoclose(request):
ttc_worker = time_to_close(app.config['Settings'])

Expand All @@ -51,6 +55,7 @@ async def timetoclose(request):


@app.route('/requestfrequency')
@compress.compress()
async def requestfrequency(request):
freq_worker = frequency(app.config['Settings'])

Expand All @@ -62,13 +67,15 @@ async def requestfrequency(request):


@app.route('/sample-data')
@compress.compress()
async def sample_route(request):
sample_dataset = {'cool_key': ['value1', 'value2'],
app.config['REDACTED']: app.config['REDACTED']}
return json(sample_dataset)


@app.route('/ingest', methods=["POST"])
@compress.compress()
async def ingest(request):
"""Accept POST requests with a list of years to import.
Query parameter name is 'years', and parameter value is
Expand All @@ -90,20 +97,23 @@ async def ingest(request):


@app.route('/update')
@compress.compress()
async def update(request):
ingress_worker = ingress_service()
return_data = ingress_worker.update()
return json(return_data)


@app.route('/delete')
@compress.compress()
async def delete(request):
ingress_worker = ingress_service()
return_data = ingress_worker.delete()
return json(return_data)


@app.route('/pins', methods=["POST"])
@compress.compress()
async def pinMap(request):
pin_worker = PinService(app.config['Settings'])
postArgs = request.json
Expand All @@ -128,6 +138,7 @@ async def requestDetails(request, srnumber):


@app.route('/test_multiple_workers')
@compress.compress()
async def test_multiple_workers(request):
Timer(10.0, print, ["Timer Test."]).start()
return json("Done")
Expand Down

0 comments on commit 8ae7602

Please sign in to comment.