-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
57 lines (48 loc) · 1.72 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
const express = require('express');
const mongoose = require('mongoose');
const session = require('express-session');
const cors = require('cors');
const authRoute = require('./routes/Auth');
const itemsRoute =require('./routes/Items');
const borrowerRoute = require('./routes/Borrower')
const categoryRoute = require('./routes/Category')
const multerRoute = require('./routes/testMulter')
//const mongoDBsession = require('connect-mongodb-session')(session)
const app = express();
require('dotenv').config();
const port = process.env.PORT || 5000
/*
Body parser in express and enable to use urlencode in postman
*/
app.use(express.json());
app.use(express.urlencoded({extended:true}));
app.use(cors());
app.use('/uploads', express.static('uploads'));
//app.use('/images', express.static(path.join(__dirname, 'images')))
//app.use(multer({storage: fileStorage, fileFilter: fileFilter}).single('image'))
//app.use(methodOverride('_method'));
// midleware route
//app.use(
// session({
// secret: 'key that will sign cookie',
// resave: false,
// saveUnitializied: false
// })
//)
app.use((req,res, next)=>{
res.setHeader('Access-Control-Allow-Origin','*');
res.setHeader('Access-Control-Allow-Methods','GET,POST,PUT,PATCH,DELETE,OPTIONS');
res.setHeader('Access-Control-Allow-Headers','Content-Type, Authorization');
next();
})
app.use('/user',authRoute);
app.use('/items',itemsRoute);
app.use('/category',categoryRoute);
app.use('/borrower',borrowerRoute);
app.use('/multer',multerRoute)
// Database Access
mongoose.connect(process.env.DATABASE,{useNewUrlParser: true, useUnifiedTopology: true},()=>
console.log('Database Connected')
);
// Port Connected
app.listen(port,()=>console.log(`Server is Runing in Port ${port}`))