-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (58 loc) · 1.85 KB
/
index.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
64
65
const express = require("express");
//Importing app from app.js
const app = require("./app");
//config .env file
require("dotenv").config();
//importing and using file and cookie middleware
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const fileUpload = require("express-fileupload");
app.use(fileUpload({ useTempFiles: true, tempFileDir: "/tmp/" }));
app.use(cookieParser());
//Regulare middleware
app.use(express.urlencoded({ extended: true }));
app.use(
bodyParser.urlencoded({
extended: true,
})
);
app.use(express.json());
//some basic logger middleware
const morgan = require("morgan");
app.use(morgan("tiny"));
//Improting and ejs and path || setting them up as well
const ejs = require("ejs");
const path = require("path");
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
//importing and using Yaml documentation and swagger-ui
const swaggerUi = require("swagger-ui-express");
const YAML = require("yamljs");
const swaggerDocument = YAML.load("./swagger.yaml");
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
//importing routes
const home = require("./routes/home");
const user = require("./routes/user");
const product = require("./routes/product");
const payment = require("./routes/payment");
const order = require("./routes/order");
//declaring routes for home
app.use("/api/v1", home);
//Declaring routes for user
app.use("/api/v1", user);
//Testing route using ejs
app.get("/signup", (req, res) => {
res.render("signup");
});
app.get("/add/product", (req, res) => {
res.render("addProduct");
});
//Decraling routes for products
app.use("/api/v1", product);
//Route for payments
app.use("api/v1", payment);
//Route for Orders
app.use("/api/v1", order);
app.listen(process.env.PORT, () => {
console.log(`The Server is running at PORT: ${process.env.PORT}`);
});