fosrl.pangolin/server/routers/badger/getConfig.ts

26 lines
828 B
TypeScript
Raw Normal View History

2024-09-28 12:35:07 -04:00
import { Request, Response, NextFunction } from 'express';
2024-09-28 12:42:38 -04:00
import { DrizzleError } from 'drizzle-orm';
import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
import { sites, Site } from '../../db/schema';
2024-09-28 14:46:36 -04:00
import db from '../../db';
2024-09-28 12:35:07 -04:00
2024-09-28 12:42:38 -04:00
export const getConfig = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
2024-09-28 12:35:07 -04:00
try {
2024-09-28 14:46:36 -04:00
const exitNodeId = req.query.exitNodeId as string;
2024-09-28 12:35:07 -04:00
if (!db) {
throw new Error('Database is not attached to the request');
}
2024-09-28 12:42:38 -04:00
const results: Site[] = db.select().from(sites).all();
2024-09-28 12:35:07 -04:00
res.json(results);
} catch (error) {
console.error('Error querying database:', error);
2024-09-28 12:42:38 -04:00
if (error instanceof DrizzleError) {
res.status(500).json({ error: 'Database query error', message: error.message });
} else {
next(error);
}
2024-09-28 12:35:07 -04:00
}
};