Delete Server directory
This commit is contained in:
1 parent
b2c8e50043
commit
3a94abb649
17 files changed
-3147
No files matched your search
@@ -1,91 +0,0 @@
|
||||
const express = require("express");
|
||||
const helmet = require("helmet");
|
||||
const cors = require("cors");
|
||||
const authRouter = require("./routes/authRoute");
|
||||
const monitorRouter = require("./routes/monitorRoute");
|
||||
const { connectDbAndRunServer } = require("./configs/db");
|
||||
require("dotenv").config();
|
||||
const logger = require("./utils/logger");
|
||||
// const { sendEmail } = require('./utils/sendEmail')
|
||||
const pingSerivce = require("./service/pingService");
|
||||
|
||||
/**
|
||||
* DB Notes
|
||||
* Here is where we can swap out DBs easily. Spin up a mongoDB instance and try it out.
|
||||
* Simply comment out the FakeDB and uncomment the MongoDB or vice versa.
|
||||
* We can easily swap between any type of data source as long as the methods are implemented
|
||||
*
|
||||
* FakeDB
|
||||
* const db = require("./db/FakeDb");
|
||||
*
|
||||
* MongoDB
|
||||
* const db = require("./db/MongoDB");
|
||||
*/
|
||||
|
||||
const DB_TYPE = {
|
||||
MongoDB: () => require("./db/MongoDB"),
|
||||
FakedDB: () => require("./db/FakeDb"),
|
||||
};
|
||||
|
||||
const db = DB_TYPE[process.env.DB_TYPE]
|
||||
? DB_TYPE[process.env.DB_TYPE]()
|
||||
: require("./db/FakeDb");
|
||||
/**
|
||||
* NOTES
|
||||
* Email Service will be added
|
||||
* Logger Service will be added (Winston or similar)
|
||||
*/
|
||||
|
||||
const app = express();
|
||||
|
||||
// middlewares
|
||||
app.use(
|
||||
cors()
|
||||
//We will add configuration later
|
||||
);
|
||||
app.use(express.json());
|
||||
app.use(helmet());
|
||||
|
||||
// **************************
|
||||
// Make DB accessible anywhere we have a Request object
|
||||
// By adding the DB to the request object, we can access it in any route
|
||||
// Thus we do not need to import it in every route file, and we can easily swap out DBs as there is only one place to change it
|
||||
// **************************
|
||||
app.use((req, res, next) => {
|
||||
req.db = db;
|
||||
next();
|
||||
});
|
||||
|
||||
//routes
|
||||
app.use("/api/v1/auth", authRouter);
|
||||
|
||||
app.use("/api/v1/monitors", monitorRouter);
|
||||
|
||||
// Testing email service
|
||||
// app.use('/sendEmail', async (req, res) => {
|
||||
// const response = sendEmail(['veysel.boybay@bluewavelabs.ca'], 'Testing email service', '<h1>Testing Bluewavelabs</h1>');
|
||||
// console.log(response);
|
||||
// })
|
||||
|
||||
//health check
|
||||
app.use("/api/v1/healthy", (req, res) => {
|
||||
try {
|
||||
logger.info("Checking Health of the server.");
|
||||
return res.status(200).json({ message: "Healthy" });
|
||||
} catch (error) {
|
||||
logger.error(error.message);
|
||||
return res.status(500).json({ message: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
connectDbAndRunServer(app, db);
|
||||
pingSerivce.startPingService(db);
|
||||
|
||||
// Cleanup
|
||||
|
||||
const cleanup = async () => {
|
||||
await pingSerivce.cleanup();
|
||||
process.exit(0);
|
||||
};
|
||||
process.on("SIGINT", cleanup);
|
||||
process.on("SIGTERM", cleanup);
|
||||
Reference in new issue
Block a user