Set up a server for your site.

Lume includes a Server class used to run a HTTP server. You can use this class to start your own server, for example, to serve the static files in Deno Deploy. Let's see a basic example of a server:

import Server from "https:/";

const server = new Server({
  port: 8000,
  root: `${Deno.cwd()}/_site`,


console.log("Listening on http://localhost:8000");

This code starts a local server on the port 8000 and serves the static files in the _site folder.


You can assign event listeners to the server:

server.addEventListener("start", () => {
  console.log("Server started successfully");


To customize how the server handles the requests and responses, there's a simple middleware system with the following signature:

server.use(async (request, next) => {
  // Here you can modify the request before being passed to next middlewares
  const response = await next(request);

  // Here you can modify the response before being returned to the previous middleware
  return response;

The request and response objects are standard Request and Response classes, no magic here.

Lume provides some middlewares for common use cases:

import Server from "https:/";
import expires from "https:/";

const server = new Server({
  port: 8000,
  root: `${Deno.cwd()}/_site`,



console.log("Listening on http://localhost:8000");


Implements the basic access authentication method to access to the site:

  users: {
    "user": "password",


Cache busting is a way to tell the browser that some static files like CSS styles or JavaScript code have changed, in order to use the new version instead of the locally cached version. It consists of including the number version in the file path. For example /styles.css becomes /v234/styles.css. More info.

This middleware implements cache busting, so all requests with paths starting with /v{numbers} will remove this part so the real file will be served.


It's a middleware to include the Expires header in the response for better caching. See the available options in Deno Doc.


To show in the console the HTTP requests/responses served. It's used by Lume in the --serve mode.


Modify the responses to disable the browser cache. It's used by Lume in the --serve mode.


To show a not-found page on 404 errors. Optionally it can create a directoryIndex for folders. It's used by Lume in the --serve mode. See the available options in Deno Doc.


To build and serve dynamic pages on demand. See the available options in Deno Doc.


Middleware to configure a list of redirects of some paths. Example:

  redirects: {
    "/from/": "/to/",
    "/from2/": "/to2/",

    // Use an object to configure the status code. (301 by default)
    "/from3/": {
      to: "/to2/",
      code: 302,
  strict: false, // configure whether distinguish the trailing slash or not (true by default)


Middleware to add additional folders to the server. Useful to serve more static files stored in a different place.

  root: "./other-folder",

// Serve the files in this folder only if they don't exist in the main folder.
  root: "./fallback-files",
  after: true,


To implement a live-reload in the browser after file changes. It's used by Lume in the --serve mode. See the available options in Deno Doc.


Useful to show a page while your site is shutted down. All request to HTML pages returns the content of the /503.html file and the 503 status code. It also sends the Retry-After header.

  page: "/maintenance.html", // The page to show. /503.html by default.
  retryAfter: 60 * 60, // The Retry-After header content in seconds. 24 hours by default.


This middleware redirects from www. domains to non-www domain (or viceversa).

  add: false, // false to remove, true to add it.

See the available options in Deno Doc.