Readme

Basic Auth for dbToAPI

This val demonstrates adding Basic auth to a dbToAPI API via Hono's [https://hono.dev/middleware/builtin/basic-auth](Basic Auth middleware). Just pass createServer an object of type {username: string; password: string}. The authentication is added to all routes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { createServer } from "https://esm.town/v/nbbaier/dbToAPI";
import { faker } from "npm:@faker-js/faker";
const db = {
data: {
posts: [
{
id: 1,
title: "Magna pars studiorum elit, prodita quaerimus.",
},
{
id: 2,
title: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
},
],
user: {
id: 1,
name: "Leanne Graham",
},
},
};
const app = await createServer(db, { auth: { username: "nb", password: "123" } });
export default app.fetch;
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
December 8, 2023