-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (34 loc) · 1.13 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
42
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
require('dotenv').config();
const authRoute = require('./routes/auth');
const categoryRoute = require('./routes/category');
const shopRoute = require('./routes/Shop');
const productRoute = require('./routes/products');
const app = express()
app.use(bodyParser.json())
app.use( (req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
res.setHeader("Access-Control-Allow-Methods", "*");
next();
});
app.use('/auth',authRoute);
app.use(productRoute);
app.use(categoryRoute);
app.use(shopRoute);
app.use('/uploads', express.static('uploads'));
app.use((error, req, res, next) =>{
const data = error.data;
const status = error.statusCode || 500;
const message = error.message || 'an error occcured';
res.status(status).json({ message: message, data: data})
})
mongoose.connect(process.env.CONNECT)
.then( result =>{
app.listen(process.env.PORT || 6000)
})
.catch( err=>{
console.log(err)
})