Basic Auth

Servest provides Basic Aauth (RFC7617) middleware by official. Add basicAuth()middleware into your router or routes.

import { createApp, basicAuth } from "https://servestjs.org/@v1.1.0/mod.ts";
const app = createApp();
// Add global auth middleware
app.use(
  basicAuth({
    credentials: [{
      username: "deno",
      password: "deno is nice",
    }, {
      username: "node",
      password: "node is awesome",
    }],
  }),
);
app.get("/", async (req) => {
  await req.respond({
    status: 200,
    headers: new Headers({
      "content-type": "text/plain",
    }),
    body: "Hello, Servest!",
  });
});
app.listen({ port: 8899 });