-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (30 loc) · 1.21 KB
/
app.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
const path = require('path');
const morgan = require('morgan');
const express = require('express');
const ApiError = require('./utils/ApiError');
const globalErrorHandle = require('./middlewares/globalErrorHandle');
const app = express();
app.use(express.json());
app.use(express.static(path.join(__dirname, 'uploads')));
if (process.env.NODE_ENV === 'development') {
app.use(morgan('dev'));
}
const categoryRoute = require('./routes/categoryRoute');
const subCategoryRoute = require('./routes/subCategoryRoute');
const brandRoute = require('./routes/brandRoute');
const productRoute = require('./routes/productRoute');
const reviewRoute = require('./routes/reviewRoute');
const userRoute = require('./routes/userRoute');
const authRoute = require('./routes/authRoute');
app.use('/api/v1/categories', categoryRoute);
app.use('/api/v1/subcategories', subCategoryRoute);
app.use('/api/v1/brands', brandRoute);
app.use('/api/v1/products', productRoute);
app.use('/api/v1/reviews', reviewRoute);
app.use('/api/v1/users', userRoute);
app.use('/api/v1/auth', authRoute);
app.all('*', (req, res, next) => {
next(new ApiError(`Can not find this route ${req.originalUrl}`, 400));
});
app.use(globalErrorHandle);
module.exports = app;