404 API Error - Azure Static Web App with Managed Python Functions

Oli 0 Reputation points
2024-10-11T12:37:09.1433333+00:00

I have a React Static Web App which was working fine until I added in managed Python Azure Functions. When running the app locally swa start build --api-location api, everything works as expected, and requests can be made to the API. However, when deploying to Azure with a deployment token, the API cannot be found 404.

I managed to get it "working" by removing all my imports from my function code, leading me to believe that it is the imports from the requirements.txt file that are not being installed, causing the API to not be available.

I am deploying by running the following commands:

  1. swa build
  2. swa deploy <config_name> --deployment-token <my_token> --verbose silly

My swa-cli.config.json file is as follows:

{
  "$schema": "https://aka.ms/azure/static-web-apps-cli/schema",
  "configurations": {
    "dml-portal": {
      "appLocation": "./",
      "apiLocation": "api",
      "outputLocation": "build",
      "apiLanguage": "python",
      "apiVersion": "3.10",
      "appBuildCommand": "npm run build",
      "run": "npm start",
      "appDevserverUrl": "http://localhost:3000"
    }
  }
}

My React app is built in the build folder, and my API is in the api folder.

My requirements.txt file looks like this:

azure-functions
msal
azure-data-tables
azure-core

All looks okay in the deployment output:

> Getting config file options from "swa-cli.config.json"...
> Changed directory to C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal
> Found configuration "dml-portal" in "swa-cli.config.json"
> Using configuration "dml-portal" from file:
>   swa-cli.config.json
> Resolving outputLocation=build full path...
> Deploying front-end files from folder:
>   C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\build
> Deploying API from folder:
>   C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\api
> Deployment token provided via flag
>  - --deployment-token: <hidden>
> Deploying to environment: preview
> Trying to read workflow config with values:
>  - appLocation: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal
>  - outputLocation: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\build
>  - apiLocation: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\api
>  - dataApiLocation: <undefined>
> No workflow config folder found at C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\.github\workflows
> Validating user workflow config (BEFORE):
>  - appLocation: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal
>  - outputLocation: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\build
>  - apiLocation: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\api
>  - dataApiLocation: <undefined>
> Validating user workflow config (AFTER):
>  - appLocation: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal
>  - apiLocation: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\api
>  - outputLocation: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\build
>  - dataApiLocation: <undefined>
> No staticwebapp.config.json found in current project
> Deploying project to Azure Static Web Apps...
> Deploying using the following options:
> - env:
>   - SWA_CLI_DEBUG: silly
>   - SWA_RUNTIME_WORKFLOW_LOCATION: <undefined>
>   - SWA_RUNTIME_CONFIG_LOCATION: <undefined>
>   - SWA_RUNTIME_CONFIG: <undefined>
>   - SWA_CLI_VERSION: 2.0.1
>   - SWA_CLI_DEPLOY_DRY_RUN: false
>   - SWA_CLI_DEPLOY_BINARY: C:\Users\Oli\.swa\deploy\19449a00c0269fefc8f29a6d01801c4b19308181\StaticSitesClient.exe@19449a00c0269fefc8f29a6d01801c4b19308181
>   - DEPLOYMENT_ACTION: upload
>   - DEPLOYMENT_PROVIDER: SwaCli
>   - REPOSITORY_BASE: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal
>   - SKIP_APP_BUILD: true
>   - SKIP_API_BUILD: true
>   - DEPLOYMENT_TOKEN: <hidden>
>   - APP_LOCATION: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\build
>   - API_LOCATION: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\api
>   - DATA_API_LOCATION: <undefined>
>   - CONFIG_FILE_LOCATION: <undefined>
>   - VERBOSE: true
>   - FUNCTION_LANGUAGE: python
>   - FUNCTION_LANGUAGE_VERSION: 3.10
>   - DEPLOYMENT_ENVIRONMENT: preview
> ℹ DeploymentId: 852dd5f2-bc2c-4577-ac21-6dasfss2524
> ℹ Verbose logging enabled
> ℹ Try to validate location at: 'C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\build'.
> ℹ Build timeout not specified, defaulting to 15 minutes
> ℹ App Directory Location: 'C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\build' was found.
> ℹ Try to validate location at: 'C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\swa-db-connections'.
> ℹ Looking for event info
> ℹ Event info parsed from action options.
> ℹ Could not get repository branch. Proceeding
> ℹ Could not get repository url. Proceeding
> ℹ Skipping step to build C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\build with Oryx
> ℹ Could not find staticwebapp.config.json file.
> ℹ Didn't find Oryx manifest file under location: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\852dd5f2-bc2c-4577-ac21-6daa399a50b8-swa-oryx\app-manifest\oryx-manifest.toml
> ℹ Determined default file to be: index.html
> ℹ Calculating the size of app artifacts: 2161429 B
> ℹ Try to validate location at: 'C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\C:\Users\Oli\OneDrive - Meganexus\Documents\Code\Projects\dml-portal\api'.
> ℹ Api Directory Location: 'C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\api' was found.
> ℹ Skipping step to build C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\api with Oryx
> ℹ Function Runtime Information. OS: linux, Functions Runtime: ~4, python version: 3.10
> ℹ Zipping Api Artifacts
> ℹ Api Zip will be created from directory: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\api
> ℹ Api Content Hash: a855e46f695619eb1b1fd4c1dd184fe2
> ℹ Done Zipping Api Artifacts
> ℹ Zipping App Artifacts
> ℹ App Zip will be created from directory: C:\Users\Oli\One Drive\Documents\Code\Projects\dml-portal\build
> ℹ Done Zipping App Artifacts
> ℹ Uploading build artifacts.
> ℹ Skipping function upload as functions are identical to last successful deployment.
> ℹ Finished Upload. Polling on deployment.
> ℹ Status: InProgress. Time: 0.0646432(s)
> ℹ Status: Succeeded. Time: 21.2915542(s)
> ℹ Deployment Complete :)
> ℹ Thanks for using Azure Static Web Apps!
> ✔ Project deployed to <my_url> 🚀

I have been stuck on this for ages, and cannot seem to find a solution. Thanks for any help on this.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,004 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
935 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.