-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
85 lines (56 loc) · 2.03 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
74
75
76
77
78
79
80
81
82
83
84
85
const express = require('express')
const app = express();
const authRoute = require('./routes/userroute')
const admin = require('./routes/adminroutes')
const product = require('./routes/productr')
const cart = require('./routes/cartroute')
const ccat= require('./routes/catroute')
//const neeew = require('./routes/new')
var unless = require('express-unless');
var mongoose = require('mongoose');
var bodyparser = require('body-parser')
const cors = require('cors')
var path = require('path')
const verify = require('./verifytoken')
const dontenv = require('dotenv');
app.use(bodyparser.urlencoded({ extended: false }));
app.use(bodyparser.json())
app.use('/uploads', express.static('uploads'));
mongoose.connect(process.env.dbconnect, {useNewUrlParser: true,useUnifiedTopology: true});
var urlencodedParser = bodyparser.urlencoded({ extended: false })
mongoose.connection.on('connected',()=>{
console.log('connected to databaseat at this port')
})
mongoose.connection.on('error',(err)=>{
if(err)
{
console.log('error in database connection')
}
})
var swaggerUi = require('swagger-ui-express'),
swaggerDocument = require('./swagger.json')
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use('/api/v1', authRoute,product,cart,ccat,admin);
// app.use(verify.unless({
// path: [
// '/api/admin',
// { url: '/', methods: ['GET', 'PUT','POST'] }
// ]
// }))
app.use('/api/user',authRoute,product,cart,ccat)
app.use('/api/admin',admin)
app.use((req, res, next) => {
const error = new Error();
error.message = 'Not Found';
error.status = 404;
next(error);
});
app.use((error, req, res, next) => {
res.status(error.status || 500).json({
error: error
});
});
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZTVlNWU4MjY4ZjA4NjFjMzQzNzY4MzUiLCJpYXQiOjE1ODMyNDI5MDd9.TWGC4v4TAhx7PDJgMrvSj4tlqJGP1gwJrTcQKGYTqOQ
//app.use(paginate.middleware(5, 5));
app.listen(3000,() => console.log('server is running on 3000'));
module.exports = app