Static Web App: API routes return 500 error without invoking functions

MLU 20 Reputation points
2026-09-17T16:56:29.5933333+00:00

Problem description

I am experiencing an issue with my Azure Static Web Apps where API routes return an empty HTTP 500 error, and no functions are being invoked. Despite the deployment appearing successful, the API endpoints do not respond as expected.

Environment

Azure Static Web Apps, Serverless API hosting, in the Central US region.

What I've already tried

I have ruled out CORS issues, missing environment variables, routing configuration problems, and have confirmed in GitHub Actions logs that the build and deployment completed successfully. I also verified that the api/ping.js function is fully self-contained and returns a hardcoded 200 response, with no shared bootstrap, secrets validation, or database clients involved. I already have an open Developer-tier support request (2609160040009134) on this issue, and the AI-driven support responses so far have not resolved it. I'm posting here as instructed by the support portal in order to continue receiving assistance on the case.

Current status

Currently, I have not confirmed a service-side cause. I am seeking guidance on how to diagnose this further, specifically how to inspect the deployed API package and configuration, or how to force the managed API build to use Node.js 18 instead of the current Node.js 22.22.0, to resolve the issue.

Azure Static Web Apps
Azure Static Web Apps

An Azure service that provides streamlined full-stack web app development.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Allan Solomon Mejia 8,840 Reputation points
    2026-09-17T18:53:55.1133333+00:00

    Hello @MLU

    Based on what you've already tested, I agree this doesn't look like a normal CORS, application-setting, or function-code failure. If even a minimal HTTP function returning a hardcoded 200 produces an empty 500 without the function being invoked, the failure is likely occurring before your handler executes.

    One clarification: Do not try to force Node.js 18. Node 18 reached end of support for Azure Static Web Apps managed APIs on May 31, 2025. The currently supported Node runtimes are Node 20 and Node 22.

    You can explicitly select the managed API runtime in staticwebapp.config.json:

    {
      "platform": {
        "apiRuntime": "node:20"
      }
    }
    

    platform.apiRuntime is the supported way to select the runtime for managed Functions.

    One thing worth checking carefully is where that file ends up after the frontend build. When there is a build step, staticwebapp.config.json must be copied to the root of the deployed output_location. Otherwise, the deployment can succeed while the platform configuration you expect isn't actually being applied.

    Therefore, test node:20, confirm from the GitHub Actions output/artifact that staticwebapp.config.json is present in the deployed output root, and redeploy.

    Also enable Application Insights on the Static Web App if you haven't already. Application Insights is the logging mechanism for managed Functions. If /api/* still returns an empty 500 and no function invocation appears there, that's useful evidence that the request is failing in the managed API/runtime layer before your code executes.

    Since you already have support request 2609160040009134, I'd add the Node 20 test and the absence of any Function invocation/telemetry to that case. If the same minimal function fails after explicitly selecting a supported runtime, don't keep changing the application code. The managed API deployment/runtime needs investigation.

    References:

    Configure Azure Static Web Apps - API runtime

    API support in Azure Static Web Apps with Azure Functions

    Static Web Apps build configuration


    Help make this community better for everyone: If this answer helped or resolved your issue, please accept it or upvote it. If not, share more details in a comment so we can continue the discussion and find the right solution. Thank you.

    Was this answer helpful?

    1 person found this answer helpful.

  2. Fabian Zankl 185 Reputation points
    2026-09-17T19:00:03.95+00:00

    Hi @MLU ,

    Your managed API on Azure Static Web Apps returns an empty HTTP 500 for every route, no function is ever invoked, and the build and deploy steps in GitHub Actions report success. You have already ruled out CORS, application settings, routing rules and the function body itself (a self-contained api/ping.js returning a fixed 200).

    Before anything else, could you share the exact contents of api/package.json (in particular the main and dependencies fields and whether a type field is present) and the folder layout of api/, including whether a host.json and any function.json files exist? Those two things tell us which programming model the host should be loading and rule the registration failures below in or out.

    Why a self-contained function can still fail before it runs

    Everything you have checked so far sits downstream of function invocation. A 500 with no invocation indicates a failure before your handler runs. One important possibility is that the Functions host discovered zero functions, or failed while loading them. In that state the function body is never reached, so its content is irrelevant to the symptom.

    The Node.js worker supports two programming models and they discover functions differently:

    • v3 model (file-based): one folder per function containing a function.json; the code is expected in index.js in the same folder unless scriptFile points elsewhere. This is the default when @azure/functions is not listed in package.json.
    • v4 model (code-centric): @azure/functions 4.x is listed under dependencies (not devDependencies), and the main field in package.json names the file or glob that calls app.http(...) to register the function. The migration guide states that host.json and package.json must be at the API root and that the main field must be defined.

    A single file at api/ping.js is not sufficient on its own. Under v3 it needs a corresponding function.json, which the host looks for at api/ping/function.json. Under v4 it must be covered by the main entry in package.json and register the function with app.http(...); if main is missing, or points somewhere else, ping.js is never required and app.http is never called. The two models also cannot be mixed: as soon as one v4 function registers, any function.json files are ignored.

    Two further variants produce the same outcome and are worth checking in the same pass:

    • A module load error in a file loaded through main (a wrong import path, a missing dependency, a "type": "module" in package.json combined with require or module.exports) can prevent the affected registration code, and potentially the registration of every function in the app, from completing. A Q&A thread from 2023 (404 static web app azure function TS) describes exactly this: the asker found a wrong import at the top of one API file, and no handlers were registered as a result. Treat this as a pattern to verify against your own code rather than an established platform rule.
    • Every external package the deployed API requires must be available at runtime, normally by being listed under dependencies in api/package.json, unless your build bundles it into the output. A package that resolves only locally (a workspace package, a global install) is missing at runtime; a 2022 Q&A thread (Azure Static Web App with Managed Functions cannot find module) shows the resulting "Cannot find module" failure for a monorepo setup.

    How to confirm it from the portal

    For managed functions the documentation directs you to Application Insights for runtime logs; logs are only available once Application Insights is added. Before that, two portal views can provide clues about whether the managed API was detected successfully:

    1. In the Static Web App resource, the APIs blade shows one row per environment with the columns Backend Type and Backend Resource Name. When the platform detected a managed functions app, Backend Type reads "Managed" for the Production environment (as described in the 2022 Q&A thread Azure Static Web App not getting response from static web api API Function); when nothing was detected, both columns show a dash. If Production shows no managed backend even though the deployment was supposed to contain api/ping.js, that is additional evidence that the managed Functions app was not detected or registered. Treat the portal state as a diagnostic clue, not as a documented statement about the exact failure stage. SWA: APIs tab Azure Portal
    2. Users report that the Application Insights blade shows "Add a function to your app to enable App Insights" when zero functions were detected. Treat that as an indicator, not a documented diagnostic contract. The same reports describe this combination, no functions listed while the Diagnose and solve problems blade still counts backend 5xx errors, as the typical signature of a function app that fails to index (Azure/static-web-apps issue #1731, and the Q&A thread StaticWebApp build/deploy job runs successfully but APIs/managed functions are not deployed correctly). Those are user observations, not documented behavior, but they match what you describe.

    Reproducing locally

    The Static Web Apps CLI runs your API through Azure Functions Core Tools and proxies /api the same way the service does; see Set up local development for Azure Static Web Apps for swa start with --api-location. Core Tools startup output normally shows the functions it discovered and often exposes module-loading or indexing errors that are otherwise hard to see in the managed environment. That output is the closest substitute for the host log you cannot see in Azure.

    On forcing Node.js 18

    @Allan Solomon Mejia answer already covers this: node:18 is out of support since May 31, 2025 per the supported runtimes table, and platform.apiRuntime in staticwebapp.config.json selects between node:20 and node:22. The point about the config file having to land in the deployed output root is worth checking as well. Switching between 20 and 22 is a legitimate test, but a registration problem of the kind described above persists across both, so if the node:20 test changes nothing, api/package.json and the folder layout are the next place to look.

    References


    Drafted with help from Claude, disclosed per the Q&A AI usage policy. All technical claims checked against the Azure Functions Node.js developer reference, the Node.js v4 migration guide, and the Azure Static Web Apps documentation on API support, supported runtimes and local development.

    Was this answer helpful?


Your answer

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