Skip to content

Commit

Permalink
Merge pull request #46 from JacobDChamberlain/chat
Browse files Browse the repository at this point in the history
Chat
  • Loading branch information
JacobDChamberlain authored Jan 4, 2025
2 parents ec8e8f6 + 5490e31 commit b1f181b
Show file tree
Hide file tree
Showing 8 changed files with 776 additions and 63 deletions.
421 changes: 398 additions & 23 deletions backend/package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
"bcrypt": "^5.1.1",
"cors": "^2.8.5",
"dotenv": "^16.4.7",
"express": "^4.21.1",
"express": "^4.21.2",
"jsonwebtoken": "^9.0.2",
"nodemailer": "^6.9.16",
"nodemon": "^3.1.7",
"pg": "^8.13.1",
"pg-hstore": "^2.3.4",
"sequelize": "^6.37.4",
"sequelize-cli": "^6.6.2",
"stripe": "^17.5.0"
"socket.io": "^4.8.1",
"stripe": "^17.5.0",
"uuid": "^11.0.3"
}
}
Empty file added backend/routes/chat.js
Empty file.
48 changes: 44 additions & 4 deletions backend/server.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,69 @@
const express = require('express');
const cors = require('cors');
const { sequelize, Item } = require('./models');
const http = require('http'); // Required to integrate WebSocket
const { Server } = require('socket.io'); // Socket.io for WebSocket support
const { v4: uuidv4 } = require('uuid');
const app = express();
const port = process.env.PORT || 5001;
require('dotenv').config();

const inventoryRoutes = require('./routes/inventory');
const checkoutRoutes = require('./routes/checkout');
const webhookRoutes = require('./routes/webhooks');
const loginRoutes = require('./routes/login');

// Middleware
app.use(express.json());
app.use(cors());
app.use(
cors({
origin: process.env.FRONTEND_URL || 'http://localhost:3000', // Frontend URL
methods: ['GET', 'POST'],
})
);

// Routes
app.use('/api/inventory', inventoryRoutes);
app.use('/api/checkout', checkoutRoutes);
app.use('/api/webhooks', webhookRoutes);
app.use('/api/login', loginRoutes);

// Create HTTP server and integrate with WebSocket
const server = http.createServer(app);
const io = new Server(server, {
cors: {
origin: process.env.FRONTEND_URL || 'http://localhost:3000', // Frontend URL
methods: ['GET', 'POST'],
},
});

// WebSocket logic
const connectedUsers = {}; // Store user IDs and associated sockets

io.on('connection', (socket) => {
const userId = uuidv4(); // Generate a unique ID for the user
connectedUsers[socket.id] = userId;

console.log(`User connected: ${userId}`);

socket.on('message', (msg) => {
// Broadcast the message with the sender's ID
io.emit('message', { userId: connectedUsers[socket.id], msg });
});

socket.on('disconnect', () => {
console.log(`User disconnected: ${connectedUsers[socket.id]}`);
delete connectedUsers[socket.id];
});
});

app.listen(port, async () => {
// Start the server
server.listen(port, async () => {
try {
await sequelize.authenticate();
console.log('Database connected! Fuck on!');
} catch (error) {
console.error('Unable to connect to the database, probably because you\'re a bitch, but here\'s an additional reason:', error);
}
console.log(`Backend server running, dont question it b`);
});
console.log(`Backend server running, don't question it b`);
});
135 changes: 135 additions & 0 deletions frontend/package-lock.json

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

69 changes: 35 additions & 34 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,47 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"bootstrap": "^5.3.3",
"react": "^18.2.0",
"react-bootstrap": "^2.10.5",
"react-dom": "^18.2.0",
"react-h5-audio-player": "^3.9.3",
"react-modal": "^3.16.1",
"react-router-dom": "^6.18.0",
"react-scripts": "5.0.1",
"react-zoom-pan-pinch": "^3.6.1",
"swiper": "^11.0.5",
"web-vitals": "^2.1.4"
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"bootstrap": "^5.3.3",
"react": "^18.2.0",
"react-bootstrap": "^2.10.5",
"react-dom": "^18.2.0",
"react-h5-audio-player": "^3.9.3",
"react-modal": "^3.16.1",
"react-router-dom": "^6.18.0",
"react-scripts": "5.0.1",
"react-zoom-pan-pinch": "^3.6.1",
"socket.io-client": "^4.8.1",
"swiper": "^11.0.5",
"web-vitals": "^2.1.4"
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11"
"@babel/plugin-proposal-private-property-in-object": "^7.21.11"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
}
2 changes: 2 additions & 0 deletions frontend/src/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { InventoryProvider } from '../../context/InventoryContext';
import SuccessfulPurchase from '../Pages/Checkout/Success/CheckoutSuccess';
import FailedPurchase from '../Pages/Checkout/Cancel/CheckoutCancel';
import CurrentStock from '../Pages/CurrentStock/CurrentStock';
import Chat from '../Pages/Chat/Chat';

function App() {
return (
Expand Down Expand Up @@ -87,6 +88,7 @@ function App() {
<Route path='/checkout' Component={ Purchase } />
<Route path='/successful-purchase' Component={ SuccessfulPurchase } />
<Route path='/sad-yeet' Component={ FailedPurchase } />
<Route path='/sup' Component={ Chat } />
<Route path='/stock' Component={ CurrentStock } />
<Route path='*' Component={ NotFound } />
</Routes>
Expand Down
Loading

0 comments on commit b1f181b

Please sign in to comment.