部署带FastAPI后端的Azure静态Web应用(SvelteKit)遇404求助
部署SvelteKit+FastAPI到Azure Static Web Apps遇到API 404错误
我正尝试将搭载FastAPI后端的SvelteKit部署至Azure Static Web Apps,目前已接近完成,但不确定这种架构是否可行。我已查阅微软相关文档、遵循svelte-adapter-azure-swa的配置步骤,且FastAPI函数单独部署时可正常运行。
SvelteKit的sk_render函数与FastAPI的WrapperFunction都放在api目录下,属于同一个staticwebapp项目。

应用部署后前端可正常渲染,但调用FastAPI接口api/hello/Jon时出现404错误。
routes/+page.svelte
<script> import { onMount } from "svelte"; let userName = "" onMount(async function () { const response = await fetch('api/hello/Jon'); const data = await response.json(); console.log(data); userName = data.name }); </script> <h1>Welcome to SvelteKit {userName}</h1> <p>Visit kit.svelte.dev to read the documentation</p>

我怀疑是host.json或function.json的配置有遗漏,以下是当前的配置文件内容:
host.json
{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[2.*, 3.0.0)" }, "extensions": { "http": { "routePrefix": "api" } } }
function.json
{ "scriptFile": "__init__.py", "bindings": [ { "authLevel": "anonymous", "type": "httpTrigger", "direction": "in", "name": "req", "methods": [ "get", "post" ], "route": "{*route}" }, { "type": "http", "direction": "out", "name": "$return" } ] }
感谢协助!
内容的提问来源于stack exchange,提问作者Jeff Tilton
相关产品推荐
相关产品推荐

