Skip to content

Returning Web Response in Azure SWA is not working #2590

Closed

Description

@targetlucked69

Environment

Nuxt: 3.12.3
Node: 20

Reproduction

Deploy a basic Nuxt app with an api that returns a web response like

export default function eventHandler((event) => {
  return new Response(JSON.stringify({ username: 'test' }), { headers: { 'Content-Type': 'application/json' } })
})

Describe the bug

Instead of the actual json, Im getting an empty object returned when deployed to Azure SWA:

// /api/user
{}

Additional context

No response

Logs

No response

Activity

  1. added
    bug
    on Jul 4, 2024
  2. transferred this issue fromh3js/h3on Jul 7, 2024
  3. itpropro commented on Oct 1, 2024

    @itpropro
    Contributor

    I was able to reproduce this. But there are alternative options to construct and send a response that work with SWA and are more "Nitro like":

    Directly returning the object (Nitro automatically sets the headers):

    export default defineEventHandler(() => {
      return { username: 'test' }
    })
    

    Using the send function:

    export default defineEventHandler((event) => {
      return send(event, JSON.stringify({ username: 'test' }), 'application/json')
      // also possible
      // return send(event, { username: 'test' }, 'application/json')
    })
    

    Both are tested and confirm to work with Azure Static Web Apps.

    Do you want to keep this issue open @pi0 or would you agree not to use the native Response object and instead use the Nitro utilities?

  4. pi0 commented on Oct 1, 2024

    @pi0
    Member

    Returning a new Response should be supported in handlers. We should investigate why body (which can be a stream) is not handled, it is a bug.

  5. itpropro commented on Oct 2, 2024

    @itpropro
    Contributor

    Returning a new Response should be supported in handlers. We should investigate why body (which can be a stream) is not handled, it is a bug.

    I verified that this is also a bug in the azure-function preset.
    The actual return value from API call is this, but Azure Static Web App filters that out:

    Body: [object ReadableStream]
    Content-Type: application/json; charset=utf-8
    

    It is definitely cause by Nitro handling the response binding for Azure Functions.

      context.res = {
        status,
        cookies: getAzureParsedCookiesFromHeaders(headers),
        headers: normalizeLambdaOutgoingHeaders(headers, true),
        body,
      };
    

    We should address that with the update to Azure Functions runtime 4.

  6. pi0 commented on Oct 2, 2024

    @pi0
    Member

    thanks for investigation @itpropro. Does runtime v4 support accept ReadableStream as valid body?

  7. itpropro commented on Oct 2, 2024

    @itpropro
    Contributor

    thanks for investigation @itpropro. Does runtime v4 support accept ReadableStream as valid body?

    No, we can also release the bug fix beforehand independently of the v4 update.

  8. jvpelt commented on Sep 17, 2025

    @jvpelt

    Hi @pi0,

    I’m running into something similar with a “tanstack start” app I’m trying to deploy to a SWA. Right now it returns a ReadableStream, but the azure functions v3 programming model doesn’t support that. A quick workaround could be to check the body type and turn the stream into a string. I can open a PR for that if you’d like.

    On the other hand, v4 does support streams. I’ve seen a few issues about upgrading to v4, but I’m not really sure what the current status is.

  9. pi0 commented on Sep 17, 2025

    @pi0
    Member

    If you can please feel free to open a PR to upgrade SWA in v3 branch.

  10. bishsbytes commented on Oct 22, 2025

    @bishsbytes

    Hi @pi0,

    I’m running into something similar with a “tanstack start” app I’m trying to deploy to a SWA. Right now it returns a ReadableStream, but the azure functions v3 programming model doesn’t support that. A quick workaround could be to check the body type and turn the stream into a string. I can open a PR for that if you’d like.

    On the other hand, v4 does support streams. I’ve seen a few issues about upgrading to v4, but I’m not really sure what the current status is.

    @jvpelt did you find a workaround for this? I'm hitting the same issue with Tanstack Start. I'm just getting a {} response.

  11. thomasschaller1 commented on Feb 24, 2026

    @thomasschaller1

    Any news about this one?

  12. derkoe commented on Apr 29, 2026

    @derkoe

    I'm using the workaround from @Xiang-CH from here https://github.com/Xiang-CH/tanstack-azure-swa-template and it works without issues.

    Can anyone have a look at their PR?

  13. added
    nuxt
    on Sep 2, 2026
  14. pi0x commented on Oct 15, 2026

    @pi0x
    Contributor

    Fixed in Nitro v3 by #4195 (azure-swa response body no longer returns {}). Closing for v2 since it is in maintenance.

    Triaged with AI assistance.

  15. added theissue type on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugnuxtpreset:azure

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions