v.0.11.3 api-server public port 8000

This commit is contained in:
tiijay
2025-11-21 19:07:41 +00:00
parent c27b97fc71
commit 115e402b0d
5 changed files with 27 additions and 19 deletions

View File

@@ -7,8 +7,9 @@
"dockerfile": "Dockerfile" "dockerfile": "Dockerfile"
}, },
"runArgs": [ "runArgs": [
"--network=dev-network", // "--network=dev-network",
"--name=api-server" "--name=api-server",
"-p", "8000:8000"
], ],
// "image": "mcr.microsoft.com/devcontainers/python:1-3.12", // "image": "mcr.microsoft.com/devcontainers/python:1-3.12",
// "image": "python:latest", // "image": "python:latest",
@@ -31,11 +32,11 @@
} }
}, },
// Use 'forwardPorts' to make a list of ports inside the container available locally. // Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [9000], "forwardPorts": [8000],
// Use 'portsAttributes' to set default properties for specific forwarded ports. // Use 'portsAttributes' to set default properties for specific forwarded ports.
// More info: https://containers.dev/implementors/json_reference/#port-attributes // More info: https://containers.dev/implementors/json_reference/#port-attributes
"portsAttributes": { "portsAttributes": {
"9000": { "8000": {
"label": "API-Server Application", "label": "API-Server Application",
"onAutoForward": "notify" "onAutoForward": "notify"
} }

View File

@@ -7,13 +7,13 @@ from app.models import Item, dummy_items
app = FastAPI(title="FastAPI Server", version="1.0.0") app = FastAPI(title="FastAPI Server", version="1.0.0")
# CORS middleware to allow client requests # CORS middleware to allow client requests
# app.add_middleware( app.add_middleware(
# CORSMiddleware, CORSMiddleware,
# # allow_origins=["http://localhost:3000", "http://client:3000"], # allow_origins=["http://localhost:3000", "http://client:3000"],
# allow_credentials=True, allow_credentials=True,
# allow_methods=["*"], allow_methods=["*"],
# allow_headers=["*"], allow_headers=["*"],
# ) )
@app.get("/") @app.get("/")

View File

@@ -7,8 +7,9 @@
"dockerfile": "Dockerfile" "dockerfile": "Dockerfile"
}, },
"runArgs": [ "runArgs": [
"--network=dev-network", // "--network=dev-network",
"--name=pico-client" "--name=pico-client",
"--add-host", "j-agent-01:192.168.178.105"
], ],
// "image": "mcr.microsoft.com/devcontainers/python:1-3.12", // "image": "mcr.microsoft.com/devcontainers/python:1-3.12",
// "image": "python:latest", // "image": "python:latest",

View File

@@ -54,10 +54,10 @@ async def main(
) -> None: ) -> None:
# Run both tasks concurrently # Run both tasks concurrently
await asyncio.gather( await asyncio.gather(
sync_ntp_time_task(), # sync_ntp_time_task(),
weather_check_task(weather_checker), # weather_check_task(weather_checker),
api_server_check_task(api_server_checker), api_server_check_task(api_server_checker),
print_time_task(), # print_time_task(),
) )

View File

@@ -1,7 +1,9 @@
import urequests # type: ignore import urequests # type: ignore
import json import json
BASE_API_URL: str = "http://api-server:8000" # BASE_API_URL: str = "http://api-server:8000"
# BASE_API_URL: str = "http://j-agent-01:8000"
BASE_API_URL: str = "http://192.168.178.105:8000"
class API_Server_Checker: class API_Server_Checker:
@@ -16,6 +18,7 @@ class API_Server_Checker:
) )
print(f"query: {items_url}") print(f"query: {items_url}")
r: any
try: try:
r = urequests.get(items_url) r = urequests.get(items_url)
print("Status-Code:", r.status_code) print("Status-Code:", r.status_code)
@@ -26,9 +29,12 @@ class API_Server_Checker:
else: else:
print("api-server error:", json_resp["error"]["message"]) print("api-server error:", json_resp["error"]["message"])
except OSError as e: except OSError as e:
print(f"api-server call failed: {e}") print("Network error:", e)
except Exception as e:
print("Error:", e)
finally: finally:
r.close() if r:
r.close()
def check(self, item_id: int): def check(self, item_id: int):
self._get_items(item_id) self._get_items(item_id)