Skip to content
This repository has been archived by the owner on Nov 7, 2021. It is now read-only.

Commit

Permalink
Server code complete
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpan05 committed Mar 1, 2020
1 parent b4f3f59 commit c58edbb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
16 changes: 16 additions & 0 deletions server/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import Flask, jsonify, make_response
import json
import werkzeug.datastructures

app = Flask(__name__)

Expand All @@ -11,3 +12,18 @@ def get(package, version):
return make_response(jsonify(data[version]), 200)
except:
return make_response(jsonify({"failure": "failure"}), 500)

def http(request):
with app.app_context():
headers = werkzeug.datastructures.Headers()
for key, value in request.headers.items():
headers.add(key, value)
with app.test_request_context(method=request.method, base_url=request.base_url, path=request.path, query_string=request.query_string, headers=headers, data=request.form):
try:
rv = app.preprocess_request()
if rv is None:
rv = app.dispatch_request()
except Exception as e:
rv = app.handle_user_exception(e)
response = app.make_response(rv)
return app.process_response(response)
11 changes: 2 additions & 9 deletions server/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ provider:

plugins:
- serverless-google-cloudfunctions
- serverless-python-requirements
- serverless-wsgi

custom:
wsgi:
app: main.app
pythonBin: python3

# needs more granular excluding in production as only the serverless provider npm
# package should be excluded (and not the whole node_modules directory)
Expand All @@ -32,9 +25,9 @@ package:

functions:
main:
handler: app
handler: http
events:
- http: ANY
- http: path
# NOTE: the following uses an "event" event (pubSub event in this case).
# Please create the corresponding resources in the Google Cloud
# before deploying this service through Serverless
Expand Down

0 comments on commit c58edbb

Please sign in to comment.