-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separated the routes ,middlewares & other setups into app.js
- Loading branch information
1 parent
207bcea
commit 1c86135
Showing
10 changed files
with
118 additions
and
109 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,3 +1 @@ | ||
node_modules | ||
Dockerfile | ||
.dockerignore | ||
node_modules |
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,41 @@ | ||
const express = require("express"); | ||
const cookieParser = require("cookie-parser"); | ||
const monogoSanitize = require("express-mongo-sanitize"); | ||
const morgan = require("morgan"); | ||
const connectDB = require("./src/db/db"); | ||
|
||
// App logic based routes | ||
const userRoute = require("./src/routes/userRoute"); | ||
const groupRoute = require("./src/routes/groupRoute"); | ||
|
||
// Initialize the app | ||
const app = express(); | ||
|
||
// Connect to the database | ||
connectDB(); | ||
|
||
// Middleware to parse JSON and urlEncoded | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
app.use(monogoSanitize()); | ||
|
||
// Cookie parser middleware | ||
app.use(cookieParser()); | ||
|
||
// HTTP request logger middleware | ||
app.use(morgan("tiny")); | ||
|
||
// Sample route to test the server | ||
app.get("/home", (req, res) => { | ||
res.status(200).json({ | ||
message: "hello visitor!", | ||
}); | ||
}); | ||
|
||
// User route middleware | ||
app.use("/user/new", userRoute); | ||
|
||
// Group create and join route middleware | ||
app.use("/handle/g", groupRoute); | ||
|
||
module.exports = app; |
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,59 +1,29 @@ | ||
require("dotenv").config(); | ||
const express = require("express"); | ||
const app = express(); | ||
const PORT = process.env.PORT; | ||
const cookieParser = require("cookie-parser"); | ||
const monogoSanitize = require("express-mongo-sanitize"); | ||
const app = require("./app"); | ||
const { | ||
pollEmailQueue, | ||
pollInviteQueue, | ||
pollBarterNotification, | ||
} = require("./src/services/emailQueueProcessor"); | ||
|
||
const connectDB = require("./src/db/db"); | ||
|
||
var morgan = require("morgan"); | ||
|
||
// call the db connection url | ||
connectDB(); | ||
|
||
// Middleware to parse json and urlEncoded | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
app.use(monogoSanitize()); | ||
|
||
// cookie parser Middleware | ||
app.use(cookieParser()); | ||
|
||
// HTTP request logger middleware | ||
app.use(morgan("tiny")); | ||
|
||
//sample route to test the server | ||
app.get("/home", (req, res) => { | ||
res.status(200).json({ | ||
message: "hello visitor !", | ||
}); | ||
}); | ||
|
||
// user route | ||
const userRoute = require("./src/routes/userRoute"); | ||
|
||
// user route middleware | ||
app.use("/user/new", userRoute); | ||
const PORT = process.env.PORT; | ||
|
||
// poll redis queues | ||
// Start polling the Redis queues | ||
pollEmailQueue(); | ||
pollInviteQueue(); | ||
pollBarterNotification(); | ||
|
||
// Start the server | ||
const server = app.listen(PORT, () => { | ||
console.log(`server is running on the port: ${PORT}`); | ||
console.log(`Server is running on port: ${PORT}`); | ||
}); | ||
|
||
// gracefully close the server (ctrl+c) | ||
// Gracefully close the server on SIGINT (Ctrl+C) | ||
process.on("SIGINT", () => { | ||
console.log(`SIGINT signal recieved, closing the server`); | ||
console.log(`SIGINT signal received, closing the server...`); | ||
|
||
server.close(() => { | ||
console.log(`Closed the HTTP server gracefully..`); | ||
console.log(`Closed the HTTP server gracefully.`); | ||
process.exit(1); | ||
}); | ||
}); |
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
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
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