Node Middleware

Qwik City Node middleware allows you to connect Qwik City to an Nodejs server which uses the common middleware functionality. Some Node servers include:

Below is an example of using the built-in Node middleware within a user's Express app. Note that the user can decide the order of the middleware, including handling static assets, and how to handle 404 responses.

import { qwikCity } from '';
import express from 'express';
import { fileURLToPath } from 'url';
import { join } from 'path';
import render from './entry.ssr';

// Directories where the static assets are located
const distDir = join(fileURLToPath(import.meta.url), '..', '..', 'dist');
const buildDir = join(distDir, 'build');

// Create the Qwik City middleware
const { router, notFound } = qwikCity(render);

// Create the express server
const app = express();

// Use Qwik City's page and endpoint router

// Static asset handlers
app.use(`/build`, express.static(buildDir, { immutable: true, maxAge: '1y', index: false }));
app.use(express.static(distDir, { index: false }));

// Use Qwik City's 404 handler

// Start the express server
Made with โค๏ธ by