Add search functionality to find articles and media outlets
Implements a search feature by adding a search modal, API endpoint, and storage logic for querying articles and media outlets. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 069d4324-6c40-4355-955e-c714a50de1ea Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3df548ff-50ae-432f-9be4-25d34eccc983/069d4324-6c40-4355-955e-c714a50de1ea/gVirbWH
This commit is contained in:
@ -354,6 +354,23 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
// Search routes
|
||||
app.get('/api/search', async (req, res) => {
|
||||
try {
|
||||
const { q } = req.query;
|
||||
|
||||
if (!q || typeof q !== 'string' || q.trim().length === 0) {
|
||||
return res.json({ outlets: [], articles: [] });
|
||||
}
|
||||
|
||||
const results = await storage.search(q.trim());
|
||||
res.json(results);
|
||||
} catch (error) {
|
||||
console.error("Error performing search:", error);
|
||||
res.status(500).json({ message: "Failed to perform search" });
|
||||
}
|
||||
});
|
||||
|
||||
const httpServer = createServer(app);
|
||||
return httpServer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user