Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const app = express();
- const port = 3000;
- const cors = require('cors');
- app.use(cors());
- // Sample book data
- const books = [
- {
- "book_title": "فن الامبالاه",
- "book_genre": "اللغة العربية",
- "book_thumbnail": "https://upload.wikimedia.org/wikipedia/ar/f/f0/%D8%BA%D9%84%D8%A7%D9%81_%D9%83%D8%AA%D8%A7%D8%A8_%D9%81%D9%86_%D8%A7%D9%84%D8%A7%D9%85%D8%A8%D8%A7%D9%84%D8%A7%D8%A9.jpg",
- "row": "1",
- "col": "1"
- },
- {
- "book_title": "صحيح مسلم بشرح الننوي",
- "book_genre": "العلوم الدينية",
- "book_thumbnail": "https://www.ibnragb.com/wp-content/uploads/2021/03/2a42f97d-199d-4c95-840e-187e0c723789.jpg",
- "row": "1",
- "col": "1"
- }
- ];
- app.get('/search', (req, res) => {
- const { book_title = '', book_genre = '' } = req.query;
- const results = books.filter(book => {
- const titleMatch = book.book_title.includes(book_title);
- const genreMatch = book_genre === '' || book.book_genre === book_genre;
- return titleMatch && genreMatch;
- });
- res.json(results);
- });
- // Start the server
- app.listen(port, () => {
- console.log(`Server is running on http://localhost:${port}`);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement