Qwik City - Middleware

Qwik City middleware is a glue code that connects server rendering framework (such as express, cloudflare-pages, etc.) with the Qwik City meta-framework.

Qwik City comes pre-bundle with:

Build

Qwik City use vite cli --ssr to specify the SSR entry

vite build --ssr src/entry.MIDDLEWARE.ts

default output dir is ./server and it is configurable by setting qwikVite plugin option

// file vite.config.ts
import { qwikVite } from "@builder.io/qwik/optimizer";

export default defineConfig(() => {
  return {
    plugins: [
      // ...other plugins
      qwikVite({
        ssr: {
          outDir: "CUSTOM_DIR",
        },
      }),
    ],
  };
});

Advanced

The requestHandler() utility is what each of the above middleware bundles uses in order to translate their request/response to a standard format for Qwik City to use. This function can be used to provide middleware for specific server frameworks.

If there's middleware missing and you'd like it added, take a look how the requestHandler() utility is used to handle requests for each of the middleware source code above. Better yet, we'd love to have your middleware contributions! PR's are welcome!