Skip to content

Commit

Permalink
Added new APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
debojitsaha committed Oct 9, 2022
1 parent 92728ff commit 6d7ba32
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 1 deletion.
1 change: 1 addition & 0 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PORT= 5000
110 changes: 110 additions & 0 deletions backend/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const chats = [
{
isGroupChat: false,
users: [
{
name: "John Doe",
email: "john@example.com",
},
{
name: "Piyush",
email: "piyush@example.com",
},
],
_id: "617a077e18c25468bc7c4dd4",
chatName: "John Doe",
},
{
isGroupChat: false,
users: [
{
name: "Guest User",
email: "guest@example.com",
},
{
name: "Piyush",
email: "piyush@example.com",
},
],
_id: "617a077e18c25468b27c4dd4",
chatName: "Guest User",
},
{
isGroupChat: false,
users: [
{
name: "Anthony",
email: "anthony@example.com",
},
{
name: "Piyush",
email: "piyush@example.com",
},
],
_id: "617a077e18c2d468bc7c4dd4",
chatName: "Anthony",
},
{
isGroupChat: true,
users: [
{
name: "John Doe",
email: "jon@example.com",
},
{
name: "Piyush",
email: "piyush@example.com",
},
{
name: "Guest User",
email: "guest@example.com",
},
],
_id: "617a518c4081150716472c78",
chatName: "Friends",
groupAdmin: {
name: "Guest User",
email: "guest@example.com",
},
},
{
isGroupChat: false,
users: [
{
name: "Jane Doe",
email: "jane@example.com",
},
{
name: "Piyush",
email: "piyush@example.com",
},
],
_id: "617a077e18c25468bc7cfdd4",
chatName: "Jane Doe",
},
{
isGroupChat: true,
users: [
{
name: "John Doe",
email: "jon@example.com",
},
{
name: "Piyush",
email: "piyush@example.com",
},
{
name: "Guest User",
email: "guest@example.com",
},
],
_id: "617a518c4081150016472c78",
chatName: "Chill Zone",
groupAdmin: {
name: "Guest User",
email: "guest@example.com",
},
},
];

module.exports= {chats}
23 changes: 23 additions & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const express= require("express")
const dotenv= require("dotenv")
const { chats } = require("./data")

const app = express()
dotenv.config()

app.get("/",(req,res)=>{
res.send("API is running")
})

app.get("/api/chat",(req,res)=>{
res.send(chats)
})

app.get("/api/chat/:id",(req,res)=>{
// console.log(req.params.id)
const singleChat= chats.find(c=>c._id===req.params.id)
res.send(singleChat)
})

const PORT = process.env.PORT || 5000
app.listen(PORT, console.log(`Server started on port ${PORT}`))
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"description": "MERN Chat App",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"start": "nodemon backend/server.js"
},
"author": "Debojit Saha",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.3",
"express": "^4.18.2"
}
}

0 comments on commit 6d7ba32

Please sign in to comment.