-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/17arindam/PlayCafe into goo…
…gle_translate
- Loading branch information
Showing
15 changed files
with
281 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
FROM node:18 AS frontend-build | ||
|
||
WORKDIR /app/frontend | ||
COPY frontend/package*.json ./ | ||
|
||
RUN npm install | ||
|
||
COPY frontend/ ./ | ||
|
||
FROM node:18 AS backend-build | ||
|
||
WORKDIR /app/backend | ||
COPY backend/package*.json ./ | ||
|
||
RUN npm install | ||
|
||
COPY backend/ ./ | ||
|
||
FROM node:18 | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=backend-build /app/backend ./backend | ||
COPY --from=frontend-build /app/frontend ./frontend | ||
|
||
COPY frontend/package*.json ./frontend/ | ||
COPY backend/package*.json ./backend/ | ||
RUN npm install --prefix frontend && npm install --prefix backend | ||
|
||
|
||
COPY start.sh ./ | ||
|
||
RUN chmod +x start.sh | ||
|
||
EXPOSE 5173 3000 | ||
|
||
|
||
CMD ["sh", "start.sh"] |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
npm-debug.log | ||
.git | ||
.gitignore | ||
README.md |
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,3 +1,4 @@ | ||
MONGO_URI=enter_your_mongo_uri | ||
EMAIL_USER=your_gmail | ||
EMAIL_PASS=your_16_digit_pass | ||
EMAIL_PASS=your_16_digit_pass | ||
JWT_SECRET=secret |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const JWT_SECRET = process.env.JWT_SECRET; | ||
const MONGO_URI = process.env.MONGO_URI; | ||
const PORT = process.env.PORT; | ||
const CORS_ORIGIN = process.env.CORS_ORIGIN; | ||
|
||
module.exports = { | ||
JWT_SECRET, | ||
MONGO_URI, | ||
PORT, | ||
CORS_ORIGIN, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const jwt = require("jsonwebtoken"); | ||
const logger = require("../config/logger"); | ||
|
||
const authenticateAdmin = (req, res, next) => { | ||
const token = req.header("Authorization")?.split(" ")[1]; // Expecting "Bearer <token>" | ||
|
||
if (token) { | ||
jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => { | ||
if (err) { | ||
return res.sendStatus(403); // Forbidden | ||
} | ||
if (decoded.role !== "admin") { | ||
return res.sendStatus(403); // Forbidden | ||
} | ||
|
||
req.user = decoded; | ||
logger.info(`Admin authenticated: ${JSON.stringify(decoded.id)}`); | ||
next(); | ||
}); | ||
} else { | ||
res.sendStatus(401); // Unauthorized | ||
} | ||
}; | ||
|
||
module.exports = authenticateAdmin; |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const jwt = require("jsonwebtoken"); | ||
const logger = require("../config/logger"); | ||
const config = require("../config/secret"); | ||
|
||
const authenticateCustomer = (req, res, next) => { | ||
const token = req.header("Authorization")?.split(" ")[1]; // Expecting "Bearer <token>" | ||
|
||
if (token) { | ||
jwt.verify(token, config.JWT_SECRET, (err, user) => { | ||
if (err) { | ||
if (err.name === "TokenExpiredError") { | ||
return res.status(401).json({ message: "Token expired" }); | ||
} | ||
return res.status(403).json({ message: "Invalid token" }); | ||
} | ||
req.user = user; | ||
logger.info(`Customer authenticated: ${JSON.stringify(user.username)}`); | ||
next(); | ||
}); | ||
} else { | ||
res.sendStatus(401); // Unauthorized | ||
} | ||
}; | ||
|
||
module.exports = authenticateCustomer; |
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
Oops, something went wrong.