-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
46 lines (39 loc) · 1.21 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
const express = require("express");
require("express-async-errors");
const cors = require("cors");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const productRoutes = require("./routes/product.js");
const orderRoutes = require("./routes/order.js");
const authRoutes = require("./routes/auth.js");
const sellerRoutes = require("./routes/seller.js");
const errorHandler = require("./middleware/errorHandler.js");
const app = express();
app.use(cors());
dotenv.config();
app.use(express.json());
app.use("/product", productRoutes);
app.use("/orders", orderRoutes);
app.use("/auth", authRoutes);
app.use("/seller", sellerRoutes);
app.use(errorHandler);
//Database initiation
mongoose.set("useUnifiedTopology", true);
let url;
if (process.env.NODE_ENV === "test")
url = "mongodb://localhost:27017/campusstoretest";
else if (process.env.NODE_ENV === "development")
url = "mongodb://localhost:27017/campusstore";
else url = process.env.MONGODB_URI || "mongodb://localhost:27017/campusstore";
mongoose.connect(
url,
{
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
},
() => {
console.log("Connected to ", url, process.env.NODE_ENV);
}
);
module.exports = app;