-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
32 lines (24 loc) · 797 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
29
30
31
32
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from typing import Dict, AnyStr, Any, List, Union
import sendMail as sm
app = FastAPI()
# TODO: adjust this for production as allowing all origins is not secure
# TODO: you could use your api gateway here as only allowed origin
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True, # allow cookies
allow_methods=["*"], # allow all methods
allow_headers=["*"], # allow all headers
)
JSONObject = Dict[AnyStr, Any]
JSONArray = List[Any]
JSONStructure = Union[JSONArray, JSONObject]
@app.get("/")
def read_root():
return {"message": "Hello World!"}
@app.post("/contact")
def contact(message: JSONStructure = None):
sm.send_mail(message)