Skip to main content
Deno 2 is finally here πŸŽ‰οΈ
Learn more

wonton πŸ₯Ÿ

npm Package deno.land/x Package License Build

A delightful http server with live reload.

Features

  • Simple CLI and API
  • Live reload
  • Light and modern
  • Secure protocol
  • SPA support
  • No dependencies

Run

By default, wonton serves ./public/ if the directory exists, otherwise the current directory ./. Any directory may be specified instead.

CLI

Run

$ # With Node.js
$ npx wonton [options] [path]

$ # With Deno
$ deno run \
    --allow-net \
    --allow-read \
    --allow-sys \
    --unstable \
    --reload \
    -- https://deno.land/x/wonton/cli.js \
    [options] \
    [path]

Install & Run

$ # With Node.js
$ npm install --global wonton

$ # With Deno
$ deno install \
    --allow-net \
    --allow-read \
    --allow-sys \
    --unstable \
    https://deno.land/x/wonton/cli.js

$ # then...
$ wonton \
    --fallback='index.html' \
    --host=0.0.0.0 \
    --live \
    --port=7000 \
    --tls-cert='/absolute/path/to/cert' \
    --tls-key='/absolute/path/to/private_key' \
    -- .

API

import serve from "wonton";

serve.start({
  fallback: "index.html",
  host: "localhost",
  live: true,
  port: 7000,
  root: ".",
  tls: {
    cert: "absolute path to cert",
    key: "absolute path to private key",
  },
});

Live Reload

CLI

$ curl http://localhost:7000/wonton-update

API

serve.update();

Use any file watcher

Watchexec

$ watchexec -- curl http://localhost:7000/wonton-update

Chokidar

import serve from "wonton";
import chokidar from "chokidar";

serve.start();

chokidar.watch(".").on("change", () => {
  serve.update();
});

esbuild

import esbuild from "esbuild";
import serve, { error, log } from "wonton";

export const isWatch = process.argv.includes("-w");

const esbuildServe = async (options = {}, serveOptions = {}) => {
  esbuild
    .build({
      ...options,
      watch: isWatch && {
        onRebuild(err) {
          serve.update();
          err ? error("βœ— Failed") : log("βœ“ Updated");
        },
      },
    })
    .catch(() => process.exit(1));

  if (isWatch) {
    serve.start(serveOptions);
  }
};

export default esbuildServe;

Log

Import the util functions to log updates with colours.

import serve, { error, log } from "wonton";

serve.update();

hasError
  ? error("βœ— Failed") // Red
  : log("βœ“ Updated"); // Green