27 lines
636 B
Python
27 lines
636 B
Python
import sqlite3
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
import uvicorn
|
|
|
|
app = FastAPI()
|
|
# Allow CORS for all origins (for simplicity)
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.get("/greetings")
|
|
async def get_greetings():
|
|
connection = sqlite3.connect("HelloWorld.db")
|
|
cursor = connection.cursor()
|
|
cursor.execute("SELECT * FROM greetings")
|
|
rows = cursor.fetchall()
|
|
return {"greetings": rows}
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run(app, host="127.0.0.1", port=8000)
|