-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (32 loc) · 977 Bytes
/
server.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
const express = require("express");
const mongoose = require("mongoose");
const authRoutes = require("./Routes/authRoutes");
const DataRoutes = require("./Routes/DataRoutes");
const TokenRoute = require("./Routes/CheckTokenRoute");
const cors = require("cors");
require("dotenv").config();
const app = express();
const corsOptions = {
origin: true,
credentials: true,
};
app.use(express.json());
app.use(cors(corsOptions));
app.use("/images", express.static("images"));
app.use("/api/admin", authRoutes);
app.use("/api/products", DataRoutes);
app.use("/api/checktoken", TokenRoute);
app.listen(`${process.env.PORT}`, () => {
console.log(`Server Started at ${process.env.PORT}`);
});
const database = mongoose.connection;
mongoose.connect(process.env.DATABASE_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
database.on("error", (error) => {
console.log(error);
});
database.once("connected", () => {
console.log("Connected to Database");
});