Basic Auth

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

// Copyright 2019 Yusuke Sakurai. All rights reserved. MIT license.
import { basicAuth } from "https://servestjs.org/@v0.36.0/middleware.ts";
import { createApp } from "https://servestjs.org/@v0.36.0/app.ts";
const app = createApp();
// Add global auth middleware
app.use(
  basicAuth({
    username: "deno",
    password: "deno is nice",
  }),
);
app.get("/", async (req) => {
  await req.respond({
    status: 200,
    headers: new Headers({
      "content-type": "text/plain",
    }),
    body: "Hello, Servest!",
  });
});
app.listen({ port: 8899 });