feat(nix): expose NixOS module and add CLI args for host/port
- Expose nixosModules.default in flake outputs for easy import - Add argparse to main.py for --host and --port CLI flags - Support priority: CLI args > env vars > defaults
This commit is contained in:
@@ -18,8 +18,11 @@
|
|||||||
flake-utils,
|
flake-utils,
|
||||||
m3ta-nixpkgs,
|
m3ta-nixpkgs,
|
||||||
agents,
|
agents,
|
||||||
} @ inputs:
|
}:
|
||||||
flake-utils.lib.eachDefaultSystem (system: let
|
{
|
||||||
|
nixosModules.default = import ./nix/module.nix;
|
||||||
|
}
|
||||||
|
// flake-utils.lib.eachDefaultSystem (system: let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
pythonPackages = pkgs.python311Packages;
|
pythonPackages = pkgs.python311Packages;
|
||||||
|
|
||||||
|
|||||||
24
src/main.py
24
src/main.py
@@ -1,8 +1,10 @@
|
|||||||
"""FastAPI application for ZUGFeRD invoice processing."""
|
"""FastAPI application for ZUGFeRD invoice processing."""
|
||||||
|
|
||||||
|
import argparse
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
@@ -147,8 +149,24 @@ async def validate_invoice_endpoint(request: ValidateRequest) -> ValidateRespons
|
|||||||
def run(host: str = "0.0.0.0", port: int = 5000) -> None:
|
def run(host: str = "0.0.0.0", port: int = 5000) -> None:
|
||||||
"""Run the FastAPI application.
|
"""Run the FastAPI application.
|
||||||
|
|
||||||
|
Priority: CLI args > env vars > defaults
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
host: Host to bind to.
|
host: Host to bind to (default from env HOST or 0.0.0.0).
|
||||||
port: Port to listen on.
|
port: Port to listen on (default from env PORT or 5000).
|
||||||
"""
|
"""
|
||||||
uvicorn.run(app, host=host, port=port)
|
parser = argparse.ArgumentParser(description="ZUGFeRD REST API Service")
|
||||||
|
parser.add_argument(
|
||||||
|
"--host",
|
||||||
|
default=os.environ.get("HOST", host),
|
||||||
|
help="Host to bind to (default: 0.0.0.0)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--port",
|
||||||
|
type=int,
|
||||||
|
default=int(os.environ.get("PORT", port)),
|
||||||
|
help="Port to listen on (default: 5000)",
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
uvicorn.run(app, host=args.host, port=args.port)
|
||||||
|
|||||||
Reference in New Issue
Block a user