This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
75 lines (58 loc) · 1.76 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
64
65
66
67
68
69
70
71
72
73
const cookieParser = require("cookie-parser");
const express = require("express");
const morgan = require('morgan')
const cors = require('cors')
const app = express();
const db = require("./models");
const figlet = require("figlet");
const inquirer = require("inquirer");
const gradient = require("gradient-string");
// config.env to
require('dotenv').config({
path: './.env'
})
app.use(cookieParser());
app.use(express.json({ limit: "50mb" }));
app.use(express.urlencoded({ limit: "50mb", extended: true }));
//config for only development
if (process.env.NODE_ENV === 'development') {
// Cors it's allow to deal with react for localhost at port {CLIENT PORT} without any problem
app.use(cors({
origin: process.env.CLIENT_URL
}))
// Morgan give information about each requrest
app.use(morgan('dev'))
}
// Routers
const imagesRoute = require("./routes/images.route");
app.use("/images", imagesRoute);
const usersRoute = require("./routes/users.route");
app.use("/user", usersRoute);
const adminRoute = require("./routes/admin.route");
app.use("/admin", adminRoute);
const ordersRoute = require("./routes/orders.route");
app.use("/order", ordersRoute);
const authRoute = require("./routes/auth.route");
app.use("/auth", authRoute);
const categoriesRoute = require("./routes/categories.route");
app.use("/categories", categoriesRoute);
app.use((req,res, next)=>{
res.status(404).json({
success: false,
message: "Page Not Founded"
})
})
const PORT = process.env.PORT
db.sequelize.sync().then(() => {
app.listen(PORT, () => {
runningServe(`SERVE ON PORT ${PORT}`);
});
});
let status;
const runningServe = async (log) => {
console.log(`\n--- ${log} ---`);
const msg = `MINEIMAGES`
figlet(msg, (err, data)=>[
console.log(gradient.pastel.multiline(data))
])
};