Search code examples
sveltesveltekit

How would an HTTP request arriving into Deno get served by Svelte?


I'm researching larger, new JS frameworks. I am normally a fullstack or backend engineer and am very familiar with server-side HTTP requests, APIs, routing etc.

With Svelte, it runs in development under its own HTTP server (maybe it's Vite doing this), AFAIK.

I'm planning on using Deno because I want to serve an API, other non-SPA pages, and I like to use middleware and control the request/responses.

So Svelte/Vite outputs some static files, bundles or whatever it does.

I can't understand how a request hits Deno and then what code decides what file on disk to read or what text to write back in the response.

I have middleware for static files like my images and robots.txt, and if that fails then it falls back to the oak router which picks a handler and my code writes a response. Easy.

But where does Svelte fit in?

What middleware do I have to write? I have been reading the docs all week and it seems to skip the part about an actual HTTP request arriving and what happens.

It feels like it's designed to be deployed into a magical serverless runtime and not to work alongside a traditional web server. Perhaps I'm getting old.

In contrast, Remix has a section in the docs which seems to make sense to me: https://remix.run/docs/en/v1/pages/technical-explanation#http-handler-and-adapters

It shows what appears to be a registration of a handler with what I assume is a middleware framework.

Please help.


Solution

  • SvelteKit is designed to work with various deployment environments and what output is generated depends entirely on the adapter being used.

    These range from the @sveltejs/adapter-static that outputs files that are meant to be served from a simple file server without any dynamic parts to e.g. the @sveltejs/adapter-node which generates an Express compatible middleware that can be integrated into a server.

    If you are using Deno you need to find or create an adapter that works for the specific middleware API you are using.