-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (45 loc) · 1.52 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
require("dotenv").config();
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const app = express();
const userController = require("./controllers/users");
const categoryController = require("./controllers/categories");
const productController = require("./controllers/products");
const reviewController = require("./controllers/reviews");
const siteController = require("./controllers/configurations");
const brandController = require("./controllers/brands");
// app.use
app.use(express.json());
app.use('/content', express.static('content/'));
app.use(express.static(__dirname + `/client/build`))
app.use(express.static(__dirname + `/admin/build`))
app.use(cors())
app.use('/api/users', userController);
app.use('/api/categories', categoryController);
app.use('/api/products', productController);
app.use('/api/reviews', reviewController);
app.use('/api/store', siteController);
app.use('/api/brands', brandController);
app.all("*", (req, res) => {
if (req.url.includes('/admin/')) {
res.sendFile(__dirname + `/admin/build/index.html`);
} else {
res.sendFile(__dirname + `/client/build/index.html`);
}
});
app.use((err, req, res, next) => {
if (err) {
res.status(400).json({ error: err.message });
} else {
next();
}
});
mongoose.connect(process.env.MONGODB_CONNECTION_URI).then(() => {
console.log("Database is connected successfully!");
}).catch(err => {
console.log(`Error`, err);
});
app.listen(5000, () => {
console.log(`App listening at Port 5000`);
});