😇

swa startで404が返される

2023/09/24に公開

static web appでデプロイ後、swa内包functionを作成して、swa start public --api-location apiでローカル環境で実行しようとしたら404が返されたのでメモ。

環境

  • React (+vite)
  • Node16
  • Azure Static Web App
  • Azure Functions v4 (swa内包)
  • swa cli v1.1.4

問題

swa start public --api-location apiを実行すると404ページに遷移し、うまく表示されない。

maru1111@LAPTOP-RK3KRPBG:~/dev-ubuntu/personal/homework/2年前期自主演習/study_bind$ swa start public --api-location api

Welcome to Azure Static Web Apps CLI (1.1.4)

***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure.                           *
***********************************************************************

[api] 
[api] Azure Functions Core Tools
[api] Core Tools Version:       4.0.5348 Commit hash: N/A  (64-bit)
[api] Function Runtime Version: 4.24.5.21262
[api] 
[api] [2023-09-24T11:35:25.645Z] Worker was unable to load entry point "dist/src/functions/*.js": Found zero files matching the supplied pattern
[api] [2023-09-24T11:35:26.493Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
[api] For detailed output, run func with --verbose flag.

[swa] 
[swa] Serving static content:
[swa]   /home/study_bind/public
[swa] 
[swa] Serving API:
[swa]   /home/study_bind/api
[swa] 
[swa] Azure Static Web Apps emulator started at http://localhost:4280. Press CTRL+C to exit.
[swa] 
[swa] 
[swa] GET http://127.0.0.1:4280/404.html - 404

解決策

swa start時のビルド成果物のディレクトリを、npm run buildしたときに出来るフォルダ名にする。
修正前

swa start public --api-location api

修正後

swa start dist --api-location api

Discussion