Modal deployment
This commit is contained in:
35
main.py
Normal file
35
main.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from pathlib import Path
|
||||
|
||||
import modal
|
||||
|
||||
import config
|
||||
|
||||
app_image = (
|
||||
modal.Image.debian_slim(python_version="3.12")
|
||||
.pip_install("lxml", "fastapi[standard]", "httpx")
|
||||
.add_local_python_source("formex_viewer", "config")
|
||||
)
|
||||
|
||||
app = modal.App("formex-viewer", image=app_image)
|
||||
|
||||
|
||||
@app.function(
|
||||
image=app_image.add_local_dir(config.ASSETS_PATH, "/assets"),
|
||||
cpu=2,
|
||||
)
|
||||
@modal.asgi_app()
|
||||
def fastapi_app():
|
||||
import fastapi.staticfiles
|
||||
|
||||
from formex_viewer.server import app as formex_app
|
||||
|
||||
assets_path = Path("/assets")
|
||||
|
||||
@formex_app.get("/{path:path}")
|
||||
async def frontend_handler(path: str):
|
||||
fp = assets_path / path
|
||||
if not fp.exists():
|
||||
fp = assets_path / "index.html"
|
||||
return fastapi.responses.FileResponse(fp)
|
||||
|
||||
return formex_app
|
||||
Reference in New Issue
Block a user