mirror of
https://github.com/Kong/insomnia.git
synced 2026-11-07 21:44:32 -05:00
Remove the misc/*-server.ts scripts and their per-server webServer entries.
Run a single mock server (misc/server), copied from insomnia-smoke-test and
adapted to native-ESM node (import.meta.dirname, .ts imports, generated
certs, no cross-package imports).
Additions on top of the smoke server: misc/server/mock-api.ts (account and
session state, _admin hooks, Cloud Sync GraphQL, vault, collaborators; runs
as middleware and falls through), an httpbin-style /post, a catch-all 200 {}
and socket.io moved to :3000. HTTP_SERVER now points at the single server.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
33 lines
882 B
TypeScript
33 lines
882 B
TypeScript
import express from 'express';
|
|
import basicAuth from 'express-basic-auth';
|
|
|
|
|
|
const getCreds = (user: string, pass: string, encoding: BufferEncoding) => ({
|
|
raw: { user, pass },
|
|
encoded: {
|
|
user: Buffer.from(user, encoding).toString(),
|
|
pass: Buffer.from(pass, encoding).toString(),
|
|
},
|
|
combined: Buffer.from(`${user}:${pass}`, encoding).toString('base64'),
|
|
});
|
|
|
|
export const basicAuthCreds = {
|
|
utf8: getCreds('user', 'pass', 'utf8'),
|
|
latin1: getCreds('user-é', 'pass-é', 'latin1'),
|
|
};
|
|
|
|
const { utf8, latin1 } = basicAuthCreds;
|
|
|
|
const users = {
|
|
[utf8.encoded.user]: utf8.encoded.pass,
|
|
[latin1.encoded.user]: latin1.encoded.pass,
|
|
};
|
|
|
|
export const basicAuthRouter = express.Router();
|
|
|
|
basicAuthRouter.use(basicAuth({ users }) as any);
|
|
|
|
basicAuthRouter.get('/', (_, res) => {
|
|
res.status(200).header('content-type', 'text/plain').send('basic auth received');
|
|
});
|