-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from haseebzaki-07/new_branch_2
Added notification for bookings
- Loading branch information
Showing
7 changed files
with
265 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,63 @@ | ||
import express from 'express'; | ||
import cors from 'cors'; | ||
import connectDB from './config/dbConnection.js'; | ||
import cookieParser from 'cookie-parser'; | ||
import express from "express"; | ||
import cors from "cors"; | ||
import connectDB from "./config/dbConnection.js"; | ||
import cookieParser from "cookie-parser"; | ||
import { createServer } from "http"; | ||
import { Server } from "socket.io"; | ||
|
||
const app = express(); | ||
const server = createServer(app); | ||
|
||
const port = process.env.PORT || 3000; | ||
|
||
app.use(cors({ | ||
origin: 'http://localhost:5173', | ||
methods: ['GET', 'POST'], | ||
allowedHeaders: ['Content-Type'], | ||
credentials: true | ||
})); // Enable CORS | ||
app.use( | ||
cors({ | ||
origin: ["http://localhost:5173", "http://127.0.0.1:5500"], | ||
methods: ["GET", "POST"], | ||
allowedHeaders: ["Content-Type"], | ||
credentials: true, | ||
}) | ||
); | ||
|
||
app.use(cookieParser()); // Parse cookies | ||
app.use(express.json()); // Parse incoming request bodies in a middleware before your handlers | ||
app.use(express.urlencoded({ extended: true })); // Parse URL-encoded bodies | ||
app.use(cookieParser()); | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: true })); | ||
|
||
// Connect to MongoDB | ||
connectDB(); | ||
|
||
// Routes | ||
import authRoutes from './routes/authRoutes.js'; | ||
import authRoutes from "./routes/authRoutes.js"; | ||
|
||
app.use('/auth', authRoutes); | ||
app.use('/api', authRoutes); | ||
app.use("/auth", authRoutes); | ||
app.use("/api", authRoutes); | ||
|
||
app.get('/', (req, res) => { | ||
res.send('Working...'); | ||
app.get("/", (req, res) => { | ||
res.send("Working..."); | ||
}); | ||
// Start the server | ||
app.listen(port, () => { | ||
|
||
|
||
|
||
const io = new Server(server, { | ||
cors: { | ||
origin: ["http://localhost:5173", "http://127.0.0.1:5500"], | ||
methods: ["GET", "POST"], | ||
credentials: true, | ||
}, | ||
}); | ||
|
||
io.on("connection", (socket) => { | ||
console.log("A user connected:", socket.id); | ||
|
||
socket.on("disconnect", () => { | ||
console.log("User disconnected:", socket.id); | ||
}); | ||
|
||
socket.on("error", (err) => { | ||
console.error("Socket error:", err); | ||
}); | ||
}); | ||
|
||
server.listen(port, () => { | ||
console.log(`Server is running on http://localhost:${port}`); | ||
}); | ||
}); | ||
|
||
export { io }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.