-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
63 lines (48 loc) · 1.74 KB
/
app.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import logging
import uvicorn
import pusher
from fastapi import FastAPI, Response, status, File, UploadFile, Form, Depends
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from typing import *
from db.database import database
from config.settings import settings
from routers import communities, councils, landcare, users, photolocations, species, events, reports
app = FastAPI()
origins = ['*']
log = logging.getLogger("backend-logger")
@app.on_event("startup")
async def startup():
app.state.db = database().get_client()
app.state.pusher_client = pusher.Pusher(
app_id = settings.pusher['app_id'],
key = settings.pusher['key'],
secret = settings.pusher['secret'],
cluster = settings.pusher['cluster'],
ssl = True
)
# SETUP UNIQUE KEYS
councils.set_unique_keys(app.state.db.data.councils)
photolocations.set_unique_keys(app.state.db.data.locations)
events.set_unique_keys(app.state.db.data.events)
users.set_unique_keys(app.state.db.data.users)
communities.set_unique_keys(app.state.db.data.communities)
reports.set_unique_keys(app.state.db.data.events)
app.include_router(communities.router)
app.include_router(events.router)
app.include_router(reports.router)
app.include_router(councils.router)
app.include_router(photolocations.router)
app.include_router(users.router)
app.include_router(species.router)
app.include_router(landcare.router)
app.mount("/files", StaticFiles(directory="files"), name="files")
# cors stuff
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_methods=["*"],
allow_headers=["*"]
)
if __name__ == '__main__':
uvicorn.run("app:app", host='0.0.0.0', port=80, reload=True)