Skip to content
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

Aniket #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PORT = 5000

DB_URL = mongodb+srv://aniketsingh2704:[email protected]/chat-app-db

JWT_SECRET = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9/g3gg34hg3h4j

NODE_ENV= development
25 changes: 0 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,26 +1 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

.env

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
# MERN Stack Project: Build and Deploy a Real Time Chat App | JWT, Socket.io

![Demo App](https://i.ibb.co/fXmZdnz/Screenshot-10.png)

[Video Tutorial on Youtube](https://youtu.be/HwCqsOis894)

Some Features:

- 🌟 Tech stack: MERN + Socket.io + TailwindCSS + Daisy UI
- 🎃 Authentication && Authorization with JWT
- 👾 Real-time messaging with Socket.io
- 🚀 Online user status (Socket.io and React Context)
- 👌 Global state management with Zustand
- 🐞 Error handling both on the server and on the client
- ⭐ At the end Deployment like a pro for FREE!
- ⏳ And much more!

### Setup .env file

Expand Down
19 changes: 12 additions & 7 deletions backend/db/connectToMongoDB.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import mongoose from "mongoose";

const url =
"mongodb+srv://aniketsingh2704:[email protected]/chat-app-db";
const connectToMongoDB = async () => {
try {
await mongoose.connect(process.env.MONGO_DB_URI);
console.log("Connected to MongoDB");
} catch (error) {
console.log("Error connecting to MongoDB", error.message);
}
try {
await mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
// Other options if needed
});
console.log("Connected to MongoDB");
} catch (error) {
console.log("Error connecting to MongoDB", error.message);
}
};

export default connectToMongoDB;
3 changes: 1 addition & 2 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import { app, server } from "./socket/socket.js";
dotenv.config();

const __dirname = path.resolve();
// PORT should be assigned after calling dotenv.config() because we need to access the env variables. Didn't realize while recording the video. Sorry for the confusion.
const PORT = process.env.PORT || 5000;

app.use(express.json()); // to parse the incoming requests with JSON payloads (from req.body)
app.use(express.json());
app.use(cookieParser());

app.use("/api/auth", authRoutes);
Expand Down
8 changes: 4 additions & 4 deletions backend/socket/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const app = express();

const server = http.createServer(app);
const io = new Server(server, {
cors: {
origin: ["http://localhost:3000"],
methods: ["GET", "POST"],
},
cors: {
origin: ["https://major-project-c61o.onrender.com"],
methods: ["GET", "POST"],
},
});

export const getReceiverSocketId = (receiverId) => {
Expand Down
2 changes: 1 addition & 1 deletion backend/utils/generateToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const generateTokenAndSetCookie = (userId, res) => {
res.cookie("jwt", token, {
maxAge: 15 * 24 * 60 * 60 * 1000, // MS
httpOnly: true, // prevent XSS attacks cross-site scripting attacks
sameSite: "strict", // CSRF attacks cross-site request forgery attacks
sameSite: "strict",
secure: process.env.NODE_ENV !== "development",
});
};
Expand Down
8 changes: 0 additions & 8 deletions frontend/README.md

This file was deleted.

311 changes: 311 additions & 0 deletions frontend/dist/assets/index-Ihe5_0Jv.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/dist/assets/index-uWxWLo0F.css

Large diffs are not rendered by default.

Binary file added frontend/dist/assets/notification-KoQ3t5UR.mp3
Binary file not shown.
Binary file added frontend/dist/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions frontend/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
<script type="module" crossorigin src="/assets/index-Ihe5_0Jv.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-uWxWLo0F.css">
</head>
<body>
<div id="root"></div>
</body>
</html>
Expand Down
1 change: 1 addition & 0 deletions frontend/dist/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion frontend/package-lock.json

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

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"chat-app-yt": "file:..",
"mern-chat-app": "file:..",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hot-toast": "^2.4.1",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { AuthContextProvider } from "./context/AuthContext.jsx";
import { SocketContextProvider } from "./context/SocketContext.jsx";

ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>

<BrowserRouter>
<AuthContextProvider>
<SocketContextProvider>
<App />
</SocketContextProvider>
</AuthContextProvider>
</BrowserRouter>
</React.StrictMode>

);
Loading