Skip to content
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
3 changes: 2 additions & 1 deletion functions/adoption/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import functions_framework

from .libs.validator import Validator
from .libs.utils import output
from .libs.queries import list_data
from .libs.network import respond_cors, respond
from .libs.network import respond_cors

@functions_framework.http
def dispatcher(request):
Expand Down
28 changes: 28 additions & 0 deletions functions/categories/libs/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

"""
Network

Handles formatting responses to match the tuple pattern required by
the flask/GCP wrapper for Cloud Functions.
"""

PREFLIGHT_HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "3600",
}

HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"}

def respond_cors():
"""
To be used to return OPTIONS responses to satisfy CORS preflight requests.
"""
return ("", 204, PREFLIGHT_HEADERS)

def respond(data, status=200):
"""
To be used to return responses to satisfy CORS requests.
"""
return (data, status, HEADERS)
16 changes: 3 additions & 13 deletions functions/categories/main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
import functions_framework

from .libs.validator import Validator
from .libs.utils import output
from .libs.queries import list_data
from .libs.network import respond_cors

@functions_framework.http
def dispatcher(request):
# For more information about CORS and CORS preflight requests, see:
# https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request

# Set CORS headers for the preflight request
if request.method == "OPTIONS":
# Allows GET requests from any origin with the Content-Type
# header and caches preflight response for an 3600s
headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "3600",
}

return ("", 204, headers)
return respond_cors()

headers = {
"Access-Control-Allow-Origin": "*",
Expand Down
28 changes: 28 additions & 0 deletions functions/cwvtech/libs/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

"""
Network

Handles formatting responses to match the tuple pattern required by
the flask/GCP wrapper for Cloud Functions.
"""

PREFLIGHT_HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "3600",
}

HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"}

def respond_cors():
"""
To be used to return OPTIONS responses to satisfy CORS preflight requests.
"""
return ("", 204, PREFLIGHT_HEADERS)

def respond(data, status=200):
"""
To be used to return responses to satisfy CORS requests.
"""
return (data, status, HEADERS)
21 changes: 5 additions & 16 deletions functions/cwvtech/main.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import functions_framework

from .libs.validator import Validator
from .libs.utils import output
from .libs.queries import list_data
from .libs.network import respond_cors

@functions_framework.http
def dispatcher(request):
# For more information about CORS and CORS preflight requests, see:
# https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request

# Set CORS headers for the preflight request

if request.method == "OPTIONS":
# Allows GET requests from any origin with the Content-Type
# header and caches preflight response for an 3600s
headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "3600",
}

return ("", 204, headers)

# Set CORS headers for the main request
return respond_cors()

headers = {
"Access-Control-Allow-Origin": "*",
"cache-control": "public, max-age=21600"
Expand Down
28 changes: 28 additions & 0 deletions functions/geos/libs/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

"""
Network

Handles formatting responses to match the tuple pattern required by
the flask/GCP wrapper for Cloud Functions.
"""

PREFLIGHT_HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "3600",
}

HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"}

def respond_cors():
"""
To be used to return OPTIONS responses to satisfy CORS preflight requests.
"""
return ("", 204, PREFLIGHT_HEADERS)

def respond(data, status=200):
"""
To be used to return responses to satisfy CORS requests.
"""
return (data, status, HEADERS)
20 changes: 4 additions & 16 deletions functions/geos/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@
from .libs.utils import output
from .libs.utils import ( COUNTRIES )
from .libs.result import Result
from .libs.network import respond_cors

@functions_framework.http
def dispatcher(request):
# For more information about CORS and CORS preflight requests, see:
# https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request

# Set CORS headers for the preflight request

if request.method == "OPTIONS":
# Allows GET requests from any origin with the Content-Type
# header and caches preflight response for an 3600s
headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "3600",
}

return ("", 204, headers)

# Set CORS headers for the main request
return respond_cors()

headers = {
"Access-Control-Allow-Origin": "*",
"cache-control": "public, max-age=21600"
Expand Down
28 changes: 28 additions & 0 deletions functions/lighthouse/libs/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

"""
Network

Handles formatting responses to match the tuple pattern required by
the flask/GCP wrapper for Cloud Functions.
"""

PREFLIGHT_HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "3600",
}

HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"}

def respond_cors():
"""
To be used to return OPTIONS responses to satisfy CORS preflight requests.
"""
return ("", 204, PREFLIGHT_HEADERS)

def respond(data, status=200):
"""
To be used to return responses to satisfy CORS requests.
"""
return (data, status, HEADERS)
21 changes: 5 additions & 16 deletions functions/lighthouse/main.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import functions_framework

from .libs.validator import Validator
from .libs.utils import output
from .libs.queries import list_data
from .libs.network import respond_cors

@functions_framework.http
def dispatcher(request):
# For more information about CORS and CORS preflight requests, see:
# https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request

# Set CORS headers for the preflight request

if request.method == "OPTIONS":
# Allows GET requests from any origin with the Content-Type
# header and caches preflight response for an 3600s
headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "3600",
}

return ("", 204, headers)

# Set CORS headers for the main request
return respond_cors()

headers = {
"Access-Control-Allow-Origin": "*",
"cache-control": "public, max-age=21600"
Expand Down
28 changes: 28 additions & 0 deletions functions/page-weight/libs/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

"""
Network

Handles formatting responses to match the tuple pattern required by
the flask/GCP wrapper for Cloud Functions.
"""

PREFLIGHT_HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "3600",
}

HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"}

def respond_cors():
"""
To be used to return OPTIONS responses to satisfy CORS preflight requests.
"""
return ("", 204, PREFLIGHT_HEADERS)

def respond(data, status=200):
"""
To be used to return responses to satisfy CORS requests.
"""
return (data, status, HEADERS)
21 changes: 5 additions & 16 deletions functions/page-weight/main.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import functions_framework

from .libs.validator import Validator
from .libs.utils import output
from .libs.queries import list_data
from .libs.network import respond_cors

@functions_framework.http
def dispatcher(request):
# For more information about CORS and CORS preflight requests, see:
# https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request

# Set CORS headers for the preflight request

if request.method == "OPTIONS":
# Allows GET requests from any origin with the Content-Type
# header and caches preflight response for an 3600s
headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "3600",
}

return ("", 204, headers)

# Set CORS headers for the main request
return respond_cors()

headers = {
"Access-Control-Allow-Origin": "*",
"cache-control": "public, max-age=21600"
Expand Down
28 changes: 28 additions & 0 deletions functions/ranks/libs/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

"""
Network

Handles formatting responses to match the tuple pattern required by
the flask/GCP wrapper for Cloud Functions.
"""

PREFLIGHT_HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "3600",
}

HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"}

def respond_cors():
"""
To be used to return OPTIONS responses to satisfy CORS preflight requests.
"""
return ("", 204, PREFLIGHT_HEADERS)

def respond(data, status=200):
"""
To be used to return responses to satisfy CORS requests.
"""
return (data, status, HEADERS)
20 changes: 4 additions & 16 deletions functions/ranks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@
from .libs.utils import output
from .libs.utils import ( RANKS )
from .libs.result import Result
from .libs.network import respond_cors

@functions_framework.http
def dispatcher(request):
# For more information about CORS and CORS preflight requests, see:
# https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request

# Set CORS headers for the preflight request

if request.method == "OPTIONS":
# Allows GET requests from any origin with the Content-Type
# header and caches preflight response for an 3600s
headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "3600",
}

return ("", 204, headers)

# Set CORS headers for the main request
return respond_cors()

headers = {
"Access-Control-Allow-Origin": "*",
"cache-control": "public, max-age=21600"
Expand Down
Loading