Files
atproto/packages/pds/tests/_oauth_client_assets_middleware.ts
Matthieu Sieben b3ce11ae2e OAuth provider UI unification (#4820)
* refactor

* tidy

* tidy
2026-04-14 16:46:18 +02:00

24 lines
685 B
TypeScript

import { IncomingMessage, ServerResponse } from 'node:http'
import files from '@atproto/oauth-client-browser-example' with { type: 'json' }
export function oauthClientAssetsMiddleware(
req: IncomingMessage,
res: ServerResponse,
next?: (err?: unknown) => void,
): void {
const path = req.url?.split('?')[0].slice(1) || 'index.html'
const file = Object.hasOwn(files, path) ? files[path] : null
if (file) {
res
.writeHead(200, 'OK', { 'content-type': file.mime })
.end(Buffer.from(file.data, 'base64'))
} else if (next) {
next()
} else {
res
.writeHead(404, 'Not Found', { 'content-type': 'text/plain' })
.end('Page not found')
}
}