Attributes
Includes Deno configuration
Repository
Current version released
2 years ago
Dependencies
Versions
wonton π₯
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 -- curl http://localhost:7000/wonton-update
import serve from "wonton";
import chokidar from "chokidar";
serve.start();
chokidar.watch(".").on("change", () => {
serve.update();
});
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