Little
A minimalistic connect-like web framework. Automatically works out of the box with Deno Deploy, Native HTTP(S) and Deno’s standard http(s) server.
Usage
// Imports
import App from "https://deno.land/x/little/mod.ts";
// Create a new application.
const app = new App();
// Add middlewares to the application.
app.use(async (ctx, next) => {
const start = Date.now();
await next();
console.log(
`${ctx.method} <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>t</mi><mi>x</mi><mi mathvariant="normal">.</mi><mi>r</mi><mi>e</mi><mi>s</mi><mi>p</mi><mi>o</mi><mi>n</mi><mi>s</mi><mi>e</mi><mo stretchy="false">?</mo><mi mathvariant="normal">.</mi><mi>s</mi><mi>t</mi><mi>a</mi><mi>t</mi><mi>u</mi><mi>s</mi><mo stretchy="false">?</mo><mo stretchy="false">?</mo><mi mathvariant="normal">"</mi><mo stretchy="false">?</mo><mo stretchy="false">?</mo><mo stretchy="false">?</mo><mi mathvariant="normal">"</mi></mrow><annotation encoding="application/x-tex">{ctx.response?.status ?? "???"} </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord"><span class="mord mathnormal">c</span><span class="mord mathnormal">t</span><span class="mord mathnormal">x</span><span class="mord">.</span><span class="mord mathnormal">res</span><span class="mord mathnormal">p</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mord mathnormal">se</span><span class="mclose">?</span><span class="mord">.</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">u</span><span class="mord mathnormal">s</span><span class="mclose">??</span><span class="mord">"</span><span class="mclose">???</span><span class="mord">"</span></span></span></span></span>{ctx.url} ${Date.now() -
start}ms`,
);
});
app.use(async (ctx) => {
await ctx.respond(new Response("Hello"));
});
// Automatically detect environment.
const strategy = app.detect({
// Define listen options,
// just incase the script
// isn't running on Deno
// Deploy.
port: 3000,
hostname: "0.0.0.0",
});
// Print the server strategy.
console.log("Using strategy", strategy);
deployctl run example.ts
# Using strategy deploy
deno run --unstable --allow-net example.ts
# Using strategy native
deno run --allow-net example.ts
# Using strategy std