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 import FastAPI, HTTPException
|
||||||
from fastapi.responses import RedirectResponse, FileResponse
|
from fastapi.responses import RedirectResponse, FileResponse
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
from dotenv import load_dotenv
|
||||||
import couchdb
|
import couchdb
|
||||||
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
import validators
|
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 = FastAPI()
|
||||||
app.mount("/static", StaticFiles(directory="static", html=True), name="static")
|
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("/")
|
@app.get("/")
|
||||||
async def root():
|
async def root():
|
||||||
|
@ -3,3 +3,4 @@ uvicorn
|
|||||||
couchdb
|
couchdb
|
||||||
aiofiles
|
aiofiles
|
||||||
validators
|
validators
|
||||||
|
python-dotenv
|
||||||
|
Loading…
x
Reference in New Issue
Block a user