-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (41 loc) · 1.29 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
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const morgan = require("morgan");
const mongoose = require("mongoose");
const cors = require("cors");
require("dotenv").config();
const authJtw = require("./helpers/jwt");
const errorHandler = require("./helpers/error-handler");
const port = 5000;
app.use(cors());
app.options("*", cors());
//middleware
app.use(bodyParser.json());
app.use(morgan("tiny"));
app.use(authJtw());
app.use('/public/uploads',express.static(__dirname + '/public/uploads'));
app.use(errorHandler);
//routers
const categoriesRouter = require("./routes/categories");
const productsRouter = require("./routes/products");
const ordersRouter = require("./routes/orders");
const usersRouter = require("./routes/users");
const api = process.env.API_URL;
app.use(`${api}/categories`, categoriesRouter);
app.use(`${api}/products`, productsRouter);
app.use(`${api}/orders`, ordersRouter);
app.use(`${api}/users`, usersRouter);
mongoose
.connect(process.env.CONNECTION_STRING, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("Connected to Mongoose");
})
.catch((err) => console.log(err));
app.listen(port, () => {
// console.log(api);
// console.log("Server is running on port " + port);
});