-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (34 loc) · 1.25 KB
/
main.py
File metadata and controls
41 lines (34 loc) · 1.25 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
from typing import Any
import json
import functions_framework # type: ignore
from flask import Request, Response
from router import RequestRouter
from database import DictionariesTable
app = RequestRouter()
dictionaries_table = DictionariesTable.from_config()
@app.route("/post", "POST", to_json=True)
def insert_dictionary(data: dict[str, Any]) -> str:
dictionary = data["dictionary"]
return dictionaries_table.insert_dictionary(dictionary)
@app.route("/get", "POST", to_json=True)
def get_dictionary(data: dict[str, Any]) -> str:
index = data["index"]
return dictionaries_table.get_dictionary(index)
@app.route("/", "GET")
def status(_: dict[str, Any]) -> str:
return """<title>UserTableFunction</title>
<H1>The function is online</H1>
"""
@functions_framework.http
def DictionariesTableFunction(request: Request) -> Response:
if request.method == "OPTIONS":
response = Response("")
response.status_code = 204
response.headers.update({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': "*",
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Max-Age': '3600'
})
return response
return app.dispatch(request)