Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds server side gzip compression #328

Merged
merged 2 commits into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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