-
Notifications
You must be signed in to change notification settings - Fork 1
Add activity feed API #44
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| const express = require('express'); | ||
| const app = express(); | ||
| const port = 3000; | ||
|
|
||
| // Fake data for the activity feed | ||
| const activityFeed = [ | ||
| { | ||
| id: 1000, | ||
| title: 'New Photo Uploaded', | ||
| body: 'Alice uploaded a new photo to her album.' | ||
| }, | ||
| { | ||
| id: 2000, | ||
| title: 'Comment on Post', | ||
| body: "Bob commented on Charlie's post." | ||
| }, | ||
| { | ||
| id: 13, | ||
| title: 'Status Update', | ||
| body: 'Charlie updated their status: "Excited about the new project!"' | ||
| } | ||
| ]; | ||
|
|
||
| app.get('/feed', (req, res) => { | ||
| res.json(activityFeed); | ||
| }); | ||
|
Comment on lines
+24
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The route handler currently lacks error handling. While the current implementation is simple, it's a good practice to wrap the logic in a app.get('/feed', (req, res) => {
try {
res.json(activityFeed);
} catch (error) {
console.error('Error fetching activity feed:', error);
res.status(500).json({ message: 'Internal Server Error' });
}
}); |
||
|
|
||
| app.listen(port, () => { | ||
| console.log(`Server running on port ${port}`); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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.
There are a couple of improvements that can be made to the initial server setup:
helmet. It sets various security-related HTTP headers that can protect your application from common web vulnerabilities. You'll need to addhelmetas a dependency (npm install helmet).