Initial commit
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
"""{{PROJECT_TITLE}} package."""
|
||||
|
||||
__version__ = "0.1.0"
|
||||
@@ -0,0 +1,32 @@
|
||||
"""Entry point for the application."""
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run the FastAPI application using uvicorn."""
|
||||
import uvicorn
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
endpoint = sys.argv[1]
|
||||
if ":" in endpoint:
|
||||
host, port = endpoint.rsplit(":", 1)
|
||||
host = host or "localhost"
|
||||
port = int(port)
|
||||
else:
|
||||
host = "localhost"
|
||||
port = int(endpoint)
|
||||
else:
|
||||
host = "localhost"
|
||||
port = {{PROD_PORT}}
|
||||
|
||||
uvicorn.run(
|
||||
"{{MODULE_NAME}}.app:app",
|
||||
host=host,
|
||||
port=port,
|
||||
log_level="info",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,40 @@
|
||||
"""Main FastAPI application."""
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi_vue import Frontend
|
||||
|
||||
# Frontend static file server - configure options here
|
||||
frontend = Frontend(
|
||||
Path(__file__).parent / "frontend-build",
|
||||
spa=True,
|
||||
favicon="/assets/favicon",
|
||||
cached=["/assets/"],
|
||||
)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""Manage app startup and shutdown resources."""
|
||||
await frontend.load()
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(title="{{PROJECT_TITLE}}", lifespan=lifespan)
|
||||
|
||||
|
||||
@app.get("/api/health")
|
||||
async def health_check():
|
||||
"""Health check endpoint for the dev server."""
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
# Add your API routes here
|
||||
# @app.get("/api/example")
|
||||
# async def example():
|
||||
# return {"message": "Hello World"}
|
||||
|
||||
|
||||
frontend.route(app, "/")
|
||||
Reference in New Issue
Block a user