-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (40 loc) · 1.28 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import express from "express";
import cors from "cors";
import mongoose from "mongoose";
import Connection from "./Database/db.js";
import Router from "./routes/route.js";
import swaggerUi from "swagger-ui-express";
import { specs } from "./swagger/swagger.Json.js";
import { firebaseConn } from "./middleware/initialiaseFirebase.js";
import { authMiddleware } from "./middleware/authController.js";
import dotenv from "dotenv";
dotenv.config();
mongoose.set("strictQuery", false);
const app = express();
const port = process.env.PORT || 8050;
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(specs));
app.use('/',authMiddleware);
app.use(express.json());
app.use(cors());
app.use("/", Router);
app.all("*", (req, res, next) => {
const err = new Error(`Can't find ${req.originalUrl} on this server`);
err.status = "fail";
err.statusCode = 404;
next(err);
});
app.use((err, req, res, next) => {
err.statusCode = err.statusCode || 500;
err.status = err.status || "error";
res.status(err.statusCode).json({
status: err.status,
message: err.message,
});
});
//credentials for mongodb database
const username = process.env.USER_NAME;
const password = process.env.PASSWORD;
Connection(username, password);
app.listen(port, () => {
console.log(`server is running on ${port}`);
});