-
Notifications
You must be signed in to change notification settings - Fork 1
Add server API #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add server API #45
Conversation
Summary of ChangesHello @bniladridas, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request establishes a foundational server-side component by adding a new Express.js application. It provides a simple API endpoint for searching and filtering a static dataset of tasks, laying the groundwork for future features that require backend data processing and retrieval. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a basic Express server with a /search API endpoint. The code is functional for its purpose. My review includes suggestions to improve configuration management by using environment variables for the port, enhance robustness by adding error handling to the API route, and follow common file formatting conventions by adding a newline at the end of the file. These changes will make the server more configurable and resilient.
| @@ -0,0 +1,33 @@ | |||
| const express = require('express'); | |||
| const app = express(); | |||
| const port = 3000; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The server port is hardcoded. It's a best practice to use environment variables for configuration like this, which allows for greater flexibility across different deployment environments (e.g., development, staging, production) without code changes.
| const port = 3000; | |
| const port = process.env.PORT || 3000; |
| app.get('/search', (req, res) => { | ||
| // Retrieve the query parameter | ||
| const query = req.query.query?.toLowerCase() || ''; | ||
|
|
||
| // Filter tasks based on the query | ||
| const filteredTasks = tasks.filter(task => task.description.toLowerCase().includes(query)); | ||
|
|
||
| res.json(filteredTasks); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The /search route handler lacks explicit error handling. If an unexpected error occurs during processing (e.g., if the tasks data were malformed in a real-world scenario), the server could become unresponsive or crash. It's safer to wrap the logic in a try...catch block to handle potential errors gracefully and return a meaningful error response to the client.
| app.get('/search', (req, res) => { | |
| // Retrieve the query parameter | |
| const query = req.query.query?.toLowerCase() || ''; | |
| // Filter tasks based on the query | |
| const filteredTasks = tasks.filter(task => task.description.toLowerCase().includes(query)); | |
| res.json(filteredTasks); | |
| }); | |
| app.get('/search', (req, res) => { | |
| try { | |
| // Retrieve the query parameter | |
| const query = req.query.query?.toLowerCase() || ''; | |
| // Filter tasks based on the query | |
| const filteredTasks = tasks.filter(task => task.description.toLowerCase().includes(query)); | |
| res.json(filteredTasks); | |
| } catch (error) { | |
| console.error('Error during search:', error); | |
| res.status(500).json({ message: 'Internal Server Error' }); | |
| } | |
| }); |
|
|
||
| app.listen(port, () => { | ||
| console.log(`Server running on port ${port}`); | ||
| }); No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
769dc13 to
34fe4df
Compare

Summary[Write a one-sentence high-level summary of the change.]
Changes
👉 Use GitHub permalinks (commit-based links).
[Add any closing statement, e.g.:]
All tests pass locally and in CI, improving reliability and maintainability.