我正在尝试使用VSCode在Azure函数上部署一个现有的快速API应用程序。
我得到这个错误:
No HTTP triggers found
我的项目结构:
这就是function.json的内容
{
"scriptFile": "backend/main.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
],
"route": "{*route}"
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
Main.py 文件中,我添加了azure函数处理程序。
import logging
import azure.functions as func
from apis.base import api_router
from core.config import settings
from db.base import Base
from db.session import engine
from db.utils import check_db_connected
from db.utils import check_db_disconnected
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from webapps.base import api_router as web_app_router
def include_router(app):
app.include_router(api_router)
app.include_router(web_app_router)
def configure_static(app):
app.mount("/static", StaticFiles(directory="static"), name="static")
def create_tables():
Base.metadata.create_all(bind=engine)
def start_application():
app = FastAPI(title=settings.PROJECT_NAME, version=settings.PROJECT_VERSION)
include_router(app)
configure_static(app)
create_tables()
return app
app = start_application()
async def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
await check_db_connected()
try:
body = await req.get_body()
return func.HttpResponse(str(body))
except Exception as e:
logging.exception('Error')
return func.HttpResponse("Error", status_code=500)
await check_db_disconnected()
我是不是漏掉了什么
我试着部署一个虚拟的API,它是成功的。改变了我的项目中的目录结构,仍然我无法将它部署到azure函数。
1条答案
按热度按时间c6ubokkw1#
No HTTP triggers found
由于用户@HariKrishna 在此问题#[75877908](在Azure上部署时看不到C# Azure函数-堆栈溢出)中显示了上述错误,因此应添加一个应用程序设置,以在任何语言运行时的连续部署场景中获取Azure函数应用程序中的函数。
该应用程序设置为:
我们无法更改Azure Functions项目的默认文件夹结构,因为它已在此MS Doc和临时解决方案中固定,如同一用户在此workaround中所示。