sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.09k stars 126 forks source link

SvelteKit: Streaming support #426

Open martinhjartmyr opened 1 month ago

martinhjartmyr commented 1 month ago

I'm trying to enable streaming support for SvelteKit.

 const app = new sst.aws.SvelteKit('App', {
      transform: {
        server: {
          streaming: true,
          timeout: '60 seconds',
        },
      }
    })

Streaming works out of the box when running sst dev vite dev.

However, when deployed to AWS, the lambda returns JSON instead of the rendered HTML (content-type: text/html):

{"statusCode":200,"headers":{"content-type":"text/html"},"body":"<!doctype html>\n<html lang=\"en\">\n\t<head>...

Example

+page.server.ts

export const load: PageServerLoad = async () => {
  return {
    _test: new Promise((resolve) => {
      setTimeout(() => {
        resolve('Hello from the server!')
      }, 3000)
    }),
  }
}

+page.svelte

<script lang="ts">
  import type { PageData } from './$types'
  export let data: PageData
</script>

{#await data._test}
  Loading ...
{:then test}
  {test}
{/await}

Am I missing something, or is this not yet implemented?

thdxr commented 1 month ago

it's not yet implemented - i'll look into this