Skip to content

Instantly share code, notes, and snippets.

@miku-orb
Created January 15, 2026 13:31
Show Gist options
  • Select an option

  • Save miku-orb/0a36748b3d765720471d4a40fba304e7 to your computer and use it in GitHub Desktop.

Select an option

Save miku-orb/0a36748b3d765720471d4a40fba304e7 to your computer and use it in GitHub Desktop.
HAN Login Test (REST web service login, from a local file)
@echo off
bun run han_login_test.ts
const server = Bun.serve({
port: "8001",
hostname: "127.0.0.1",
routes: {
"/han_login": {
POST: async req => {
const data = await import("./han_login_test_users.toml");
const users = data.users as { username: string; password: string }[];
const body = await req.json();
const valid = users.some(u => u.username === body.user && u.password === body.pass);
const our_response = { valid };
console.log({ req, body, our_response });
return Response.json(our_response);
},
},
},
fetch(req) {
console.log("Not found fallback", { req });
return new Response("Not Found", { status: 404 });
},
});
console.log(`Server running at ${server.url}`);
// In HAN Cconfig:
// Description: REST web service Login
// Label: LOCAL-FILE-TEST
// Service configuration
// PasswordField: pass
// UserAgent: Test
// UserField: user
// Url: https://127.0.0.1:8001/han_login
// ResponseField: valid
[[users]]
username = "user1"
password = "pass1"
[[users]]
username = "user2"
password = "pass2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment