-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
59 lines (53 loc) · 1.73 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
require('dotenv').config();
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const fileUpload = require('express-fileupload');
const cookieParser = require('cookie-parser');
const router = require('./routes/userRoutes');
const app = express();
app.use(express.json());
app.use(cookieParser());
app.use(fileUpload({
useTempFiles: true,
}));
app.use(cors({
'allowedHeaders': ['sessionId', 'Content-Type'],
'exposedHeaders': ['sessionId'],
'origin': '*',
'methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
'preflightContinue': false
}));
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
next();
});
// all the routes of the server.
app.use('/users', router);
app.use('/api', require('./routes/categoryRoutes'));
app.use('/api', require('./routes/upload'));
app.use('/api', require('./routes/productRoutes'));
app.use('/api', require('./routes/paymentRouter'));
app.use('/api', require('./routes/reviewRoutes'));
// connection to our database.
// const URI = process.env.MONGODB_URL;
mongoose.connect('mongodb://localhost:27017/ECOMWEB', {
useNewUrlParser:true,
useUnifiedTopology:true,
// useFindAndModify:false,
// useCreateIndex:true,
}, error => {
if(error) throw error;
console.log('connected to our database.')
});
app.get('/', (req, res) =>{
res.json({
message: "Anshuman Sharma"
});
});
const PORT = process.env.PORT || 4000;
app.listen(PORT, () => {
console.log('server is running on port ', PORT);
})