Compare commits
2 Commits
uebung_ent
...
main
Author | SHA1 | Date |
---|---|---|
|
d1f0ff3375 | |
|
569589a4f5 |
|
@ -1,4 +1,5 @@
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
|
/env
|
Binary file not shown.
13
README.md
13
README.md
|
@ -1,4 +1,13 @@
|
||||||
# IWS_clean_architecture
|
# IWS_clean_architecture
|
||||||
|
|
||||||
** Master MDS HSMA **
|
** Master MDS HSMA **
|
||||||
Clean Architecture - Architekturstil am praktischen Beispiel z.B. in Python.
|
Clean Architecture - Architekturstil am praktischen Beispiel z.B. in Python.
|
||||||
|
|
||||||
|
## Setup Test
|
||||||
|
1. falls python noch nicht installiert, installieren
|
||||||
|
2. navigiere zum repo ```cd IWS_WS24_clean_architecture```
|
||||||
|
3. ```pip install -r requirements.txt```
|
||||||
|
4. ```python main.py``` ausführen und Terminal offen lassen
|
||||||
|
5. index.html mit Browser öffnen
|
||||||
|
6. Wenn alles geklappt hat sollte die index.html Hello World anzeigen
|
||||||
|
7. mit ```STRG + C``` kann das script im Terminal gestoppt werden
|
|
@ -0,0 +1,26 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Setup Test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1 id="greetings">Not Working</h1>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Fetch Hello World from the FastAPI endpoint
|
||||||
|
fetch('http://127.0.0.1:8000/greetings')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
const greetingsContainer = document.getElementById('greetings');
|
||||||
|
greetingsContainer.innerHTML = '';
|
||||||
|
data.greetings.forEach(greeting => {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.textContent = `${greeting[1]}`;
|
||||||
|
greetingsContainer.appendChild(div);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,26 @@
|
||||||
|
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)
|
|
@ -0,0 +1,2 @@
|
||||||
|
fastapi
|
||||||
|
uvicorn
|
Loading…
Reference in New Issue