Init db and and use dotenv to load database credentials
This commit is contained in:
parent
cd74846a7f
commit
f3a858956e
16
api.py
16
api.py
@ -1,14 +1,28 @@
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.responses import RedirectResponse, FileResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from dotenv import load_dotenv
|
||||
import couchdb
|
||||
import os
|
||||
import uuid
|
||||
import validators
|
||||
|
||||
load_dotenv()
|
||||
|
||||
COUCHDB_USER = os.getenv("COUCHDB_USER")
|
||||
COUCHDB_PASSWORD = os.getenv("COUCHDB_PASSWORD")
|
||||
COUCHDB_HOST = os.getenv("COUCHDB_HOST")
|
||||
COUCHDB_PORT = os.getenv("COUCHDB_PORT")
|
||||
|
||||
app = FastAPI()
|
||||
app.mount("/static", StaticFiles(directory="static", html=True), name="static")
|
||||
|
||||
couch = couchdb.Server("http://admin:password@127.0.0.1:5984")
|
||||
couch = couchdb.Server(f"http://{COUCHDB_USER}:{COUCHDB_PASSWORD}@{COUCHDB_HOST}:{COUCHDB_PORT}")
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
if 'urls' not in couch:
|
||||
couch.create_database('urls')
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
|
@ -3,3 +3,4 @@ uvicorn
|
||||
couchdb
|
||||
aiofiles
|
||||
validators
|
||||
python-dotenv
|
||||
|
Loading…
x
Reference in New Issue
Block a user