-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (53 loc) · 1.6 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const ejs = require("ejs");
const morgan = require("morgan");
const cloudinary = require("cloudinary");
const cookieParser = require("cookie-parser");
const fileUpload = require("express-fileupload");
const swaggerUi = require("swagger-ui-express");
const YAML = require("yamljs");
const app = express();
const swaggerDocument = YAML.load("./swagger.yaml");
//cloudinary configuration..
cloudinary.config({
cloud_name: process.env.CLOUDINARY_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_SECRET_KEY,
});
//middlewares....
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(morgan("tiny"));
app.set("view engine", "ejs");
app.use(
fileUpload({
useTempFiles: true,
tempFileDir: "/tmp/",
})
);
//routes.....goes here...
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use("/api/v1/user", require("./routes/user"));
app.use("/api/v1/products", require("./routes/product"));
app.use("/api/v1/paymentMethod", require("./routes/paymentRoute"));
app.use("/api/v1/order", require("./routes/order"));
app.get("/", (req, res) => {
res.render("signup");
});
const PORT = process.env.PORT || 8000;
//db connection....and starting the server....
mongoose
.connect(process.env.URI)
.then(() => {
console.log("DB connected");
app.listen(PORT, () => {
console.log(`server runs on port: ${PORT}😄`);
});
})
.catch((err) => {
console.log(err);
process.exit(1);
});