Skip to content

Add activity feed API#7

Open
dejarno wants to merge 1 commit into
mainfrom
10-13-demo_15213232_add_activity_feed_api
Open

Add activity feed API#7
dejarno wants to merge 1 commit into
mainfrom
10-13-demo_15213232_add_activity_feed_api

Conversation

@dejarno

@dejarno dejarno commented Oct 13, 2025

Copy link
Copy Markdown
Owner

TL;DR

Added a basic Express server with a mock activity feed endpoint.

What changed?

Created a new server.js file in the graphite-demo directory that:

  • Sets up an Express server running on port 3000
  • Defines a mock activity feed with sample data
  • Implements a GET /feed endpoint that returns the activity feed as JSON

How to test?

  1. Install dependencies: npm install express
  2. Start the server: node graphite-demo/server.js
  3. Access the endpoint: curl http://localhost:3000/feed or visit in a browser
  4. Verify that the response contains the mock activity feed data

Why make this change?

This provides a simple backend API for the graphite demo application to fetch activity feed data, enabling frontend development without requiring a full backend implementation. The mock data allows for testing the activity feed display functionality.

Summary by CodeRabbit

  • New Features
    • Introduces a lightweight HTTP server that serves a static activity feed.
    • Provides a GET /feed endpoint returning JSON items (id, title, body).
    • Returns standard JSON with appropriate content type for easy consumption.
    • Starts on port 3000 and logs a confirmation on startup.
    • Feed data is static; updates require restarting the server.
    • No authentication or error handling is included in this initial version.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai

coderabbitai Bot commented Oct 13, 2025

Copy link
Copy Markdown

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “Add activity feed API” concisely and accurately describes the primary change—introducing a mock activity feed endpoint—making it clear and specific without extraneous detail.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 10-13-demo_15213232_add_activity_feed_api

Comment @coderabbitai help to get the list of available commands and usage tips.

dejarno commented Oct 13, 2025

Copy link
Copy Markdown
Owner Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@dejarno dejarno marked this pull request as ready for review October 13, 2025 11:48

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
graphite-demo/server.js (4)

1-3: Consider making the port configurable via environment variables.

Hardcoding the port works for a quick demo, but making it configurable improves flexibility for different environments.

Apply this diff to make the port configurable:

-const port = 3000;
+const port = process.env.PORT || 3000;

5-22: Consider adding timestamps to activity feed items.

For a more realistic activity feed, consider adding timestamp fields to each item. This would make the mock data more useful for frontend development and testing time-based features.

Example structure:

const activityFeed = [
  {
    id: 1000,
    title: 'New Photo Uploaded',
    body: 'Alice uploaded a new photo to her album.',
    timestamp: new Date().toISOString()
  },
  // ... other items
];

24-26: Consider adding CORS support for cross-origin requests.

If the frontend runs on a different origin (e.g., a separate development server), you'll need CORS configured. While this works for basic testing, adding CORS support early prevents issues during frontend integration.

Install the cors package and apply this diff:

 const express = require('express');
+const cors = require('cors');
 const app = express();
+app.use(cors());
 const port = process.env.PORT || 3000;

Install command:

npm install cors

28-30: Consider adding error handling for server startup.

Adding basic error handling helps catch common issues like port conflicts during development.

Apply this diff to add error handling:

-app.listen(port, () => {
-  console.log(`Server running on port ${port}`);
-});
+app.listen(port, () => {
+  console.log(`Server running on port ${port}`);
+}).on('error', (err) => {
+  if (err.code === 'EADDRINUSE') {
+    console.error(`Port ${port} is already in use`);
+  } else {
+    console.error('Server error:', err);
+  }
+  process.exit(1);
+});
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f73b91 and 4ec348d.

📒 Files selected for processing (1)
  • graphite-demo/server.js (1 hunks)

Comment thread graphite-demo/server.js
@@ -0,0 +1,30 @@
const express = require('express');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify express is listed in package.json dependencies.

The PR instructions mention manually installing express, which suggests it may not be tracked in package.json yet. Ensure express is added as a dependency for proper dependency management.

Run the following script to check if express is in package.json:


🏁 Script executed:

#!/bin/bash
# Check if express is listed as a dependency in package.json

if [ -f "package.json" ]; then
  echo "Checking package.json for express dependency..."
  cat package.json | jq '.dependencies.express // .devDependencies.express // "NOT FOUND"'
else
  echo "package.json not found in repository root"
fi

Length of output: 59


Add express to package.json dependencies
server.js requires express but it’s missing from package.json. Run npm install express --save or add it manually.

🤖 Prompt for AI Agents
In graphite-demo/server.js around line 1, the file requires 'express' but
package.json does not include express as a dependency; add express to
package.json dependencies (or run npm install express --save) and then run npm
install to update node_modules, ensuring package.json and package-lock.json are
committed.

Comment thread graphite-demo/server.js
body: "Bob commented on Charlie's post."
},
{
id: 13,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix the inconsistent ID pattern.

The ID value 13 breaks the pattern established by the previous IDs (1000, 2000). This appears to be a typo and should likely be 3000 or follow a sequential pattern.

Apply this diff to maintain consistency:

-    id: 13,
+    id: 3000,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
id: 13,
id: 3000,
🤖 Prompt for AI Agents
In graphite-demo/server.js around line 18, the id value is set to 13 which
breaks the established ID pattern (1000, 2000); replace the incorrect 13 with
the consistent value (e.g., 3000 or the next sequential ID) so the IDs follow
the same pattern and update any related references if necessary.

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2025

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant