Adaptors and Middleware

Qwik City middleware is a glue code that connects server rendering framework (such as Cloudflare, Netlify, Express etc.) with the Qwik City meta-framework.

Qwik City comes pre-bundle with:

Build

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

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

default output directory 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 at 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!

Made with ❤️ by