-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
28 lines (22 loc) · 902 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import asyncio
import functions_framework
from daily_pulse.handler.common import handler
from daily_pulse.config import config
@functions_framework.http
def daily_pulse(request) -> str:
if not request.headers.get("x-dailypulse-authorization") == f"Bearer {config['AUTH_CODE']}":
return "Authorization header invalid", 403
if request.method == "OPTIONS":
headers = {
"Access-Control-Allow-Origin": config["ORIGIN_DOMAIN"],
"Access-Control-Allow-Methods": "POST",
"Access-Control-Allow-Headers": "Authorization",
"Access-Control-Max-Age": "3600",
"Access-Control-Allow-Credentials": "true",
}
return ("", 204, headers)
headers = {
"Access-Control-Allow-Origin": config["ORIGIN_DOMAIN"],
"Access-Control-Allow-Credentials": "true",
}
return asyncio.run(handler(request))