Fix production TypeScript builds and add DEPLOY.md so the app can be hosted from this repo. Co-authored-by: Cursor <cursoragent@cursor.com>
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { createApp } from '../src/app.js';
|
|
import { checkDatabaseHealth } from '../src/lib/prisma.js';
|
|
|
|
export type JsonResponse = {
|
|
success?: boolean;
|
|
data?: Record<string, unknown>;
|
|
error?: { code?: string; message?: string; details?: unknown };
|
|
meta?: { requestId?: string };
|
|
};
|
|
|
|
export function createTestApp() {
|
|
return createApp();
|
|
}
|
|
|
|
export async function isDatabaseAvailable(): Promise<boolean> {
|
|
try {
|
|
return await checkDatabaseHealth();
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function authHeader(token: string): HeadersInit {
|
|
return {
|
|
Authorization: `Bearer ${token}`,
|
|
'Content-Type': 'application/json',
|
|
};
|
|
}
|
|
|
|
export async function requestJson(
|
|
app: ReturnType<typeof createApp>,
|
|
path: string,
|
|
init: RequestInit = {},
|
|
): Promise<{ status: number; body: JsonResponse; raw: string }> {
|
|
const headers = new Headers(init.headers);
|
|
if (init.body && !headers.has('Content-Type')) {
|
|
headers.set('Content-Type', 'application/json');
|
|
}
|
|
|
|
const response = await app.fetch(new Request(`http://localhost${path}`, { ...init, headers }));
|
|
const raw = await response.text();
|
|
let body: JsonResponse = {};
|
|
try {
|
|
body = JSON.parse(raw) as JsonResponse;
|
|
} catch {
|
|
body = {};
|
|
}
|
|
|
|
return { status: response.status, body, raw };
|
|
}
|
|
|
|
export function assertNoSecrets(raw: string): void {
|
|
if (/passwordHash/i.test(raw) || /tokenHash/i.test(raw) || /\$argon2/i.test(raw)) {
|
|
throw new Error(`Response leaked authentication secrets: ${raw}`);
|
|
}
|
|
}
|