-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38b646a
commit d121ca8
Showing
16 changed files
with
110 additions
and
82 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 |
---|---|---|
@@ -1,52 +1,55 @@ | ||
// Basic Lib Imports | ||
const express = require("express"); // Importing the Express framework for building web applications | ||
const helmet = require("helmet"); // Importing Helmet middleware for securing HTTP headers | ||
const bodyParser = require('body-parser'); // Importing Body Parser middleware for parsing request bodies | ||
const cookieParser = require('cookie-parser'); // Importing Cookie Parser middleware for parsing cookies | ||
require("dotenv").config(); // Loading environment variables from .env file | ||
const cors = require('cors'); // Importing CORS middleware for enabling Cross-Origin Resource Sharing | ||
const { errorHandler } = require("./middleware/errorMiddleware"); // Importing custom error handling middleware | ||
|
||
// Database connection with mongoose | ||
const connectDB = require("./config/db"); // Importing database connection function using Mongoose | ||
connectDB(); // Establishing the database connection | ||
|
||
|
||
|
||
const app = express(); // Creating an instance of the Express application | ||
app.use('/uploads', express.static(__dirname + '/uploads')); // Serve uploaded files from the 'uploads' folder | ||
|
||
app.use(helmet()); // Setting up Helmet middleware for securing HTTP headers | ||
app.use(bodyParser.json()); // Parsing JSON bodies | ||
app.use(cookieParser()); // Parsing cookies | ||
app.use(express.json()); // Parsing JSON bodies | ||
const express = require("express"); | ||
const helmet = require("helmet"); | ||
const bodyParser = require('body-parser'); | ||
const cookieParser = require('cookie-parser'); | ||
require("dotenv").config(); | ||
const cors = require('cors'); | ||
const { errorHandler } = require("./app/middleware/errorMiddleware"); | ||
const connectDB = require("./config/db"); | ||
connectDB(); | ||
|
||
const applicationRoutes = require('./app/routes/index'); | ||
|
||
|
||
const app = express(); | ||
|
||
app.use('/uploads', express.static(__dirname + '/uploads')); | ||
app.use(helmet()); | ||
app.use(bodyParser.json()); | ||
app.use(cookieParser()); | ||
app.use(express.json()); | ||
app.use(cors( | ||
{ | ||
origin: `${process.env.FRONTEND_URL}`, | ||
credentials: true | ||
} | ||
)); // Enabling CORS for localhost origins | ||
)); | ||
app.use( | ||
express.urlencoded({ | ||
extended: false, | ||
}) | ||
); | ||
|
||
// Routing Implement | ||
app.use("/api/v1/users", require("./routes/userRouters")); // Mounting userRouters for handling user-related routes | ||
app.use("/api/v1/posts", require("./routes/postRouters")); // Mounting postRouters for handling task-related routes | ||
app.use('/api/v1/', applicationRoutes); | ||
|
||
// Health Check | ||
app.use("/health", (req, res) => { | ||
res.status(200).json({ status: 200, success: true, message: "Health OK✅" }); | ||
res.status(200).json({ status: 200, success: true, message: "Health OK🔥" }); | ||
}); | ||
|
||
// Root | ||
app.use("/", (req, res) => { | ||
res.status(200).json({ status: 200, success: true, message: "If you saw this, it's because our servers are working ✅." }); | ||
}); | ||
|
||
// Undefined Route Implement | ||
app.use("*", (req, res) => { | ||
res.status(404).json({ status: 404, message: "Not Found" }); | ||
res.status(404).json({ status: 404, success: false, message: "Not Found" }); | ||
}); | ||
|
||
// Custom error handler | ||
app.use(errorHandler); | ||
|
||
module.exports = app; // Exporting the Express app for external use | ||
module.exports = app; |
2 changes: 1 addition & 1 deletion
2
middleware/authMiddleware.js → app/middleware/authMiddleware.js
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
File renamed without changes.
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
File renamed without changes.
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,28 @@ | ||
// Basic Lib Imports | ||
const express = require('express'); | ||
const router = express.Router(); | ||
|
||
const { | ||
createAccountLimiter, | ||
forgetPasswordLimiter, | ||
verifyLimiter, | ||
} = require('../../../services/rateLimitService'); | ||
|
||
const { | ||
registerUser, | ||
emailVerify, | ||
loginUser, | ||
logoutUser, | ||
forgetPassword, | ||
resetPassword, | ||
} = require('./auth.controller'); | ||
|
||
// Routing Implement | ||
router.post('/register', createAccountLimiter, registerUser); | ||
router.post('/verify', verifyLimiter, emailVerify); | ||
router.post('/login', loginUser); | ||
router.post('/reset-password', resetPassword); | ||
router.post('/logout', logoutUser); | ||
router.post('/forgot-password', forgetPasswordLimiter, forgetPassword); | ||
|
||
module.exports = router; |
6 changes: 3 additions & 3 deletions
6
controllers/postController.js → app/modules/post/post.controller.js
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
4 changes: 2 additions & 2 deletions
4
controllers/userController.js → app/modules/user/user.controller.js
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
File renamed without changes.
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,20 @@ | ||
// Basic Lib Imports | ||
const express = require('express'); | ||
|
||
const router = express.Router(); | ||
|
||
|
||
const authRouters = require('../modules/auth/auth.route'); | ||
const userRouters = require('../modules/user/user.route'); | ||
const postRouters = require('../modules/post/post.route'); | ||
|
||
|
||
const moduleRoutes = [ | ||
{ path: '/auth', route: authRouters }, | ||
{ path: '/users', route: userRouters }, | ||
{ path: '/posts', route: postRouters }, | ||
]; | ||
|
||
moduleRoutes.forEach((route) => router.use(route.path, route.route)); | ||
|
||
module.exports = applicationRoutes = router; |
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 was deleted.
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