require('dotenv').config();

const app = require('express')();
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const cors = require('cors');

const port = process.env.PORT || 3000
let index = require('./routes/index');
let transaction = require('./routes/transaction')
let propertySell = require('./routes/propertySell')
let propertyRent = require('./routes/propertyRent')
let request = require('./routes/request')
let access = require('./routes/access')
let category = require('./routes/category')
let user = require('./routes/user')
let admin = require('./routes/admin')
let roomRent = require('./routes/roomRent')
let roomSell = require('./routes/roomSell')
let testimony = require('./routes/testimony')

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}));

app.use('/', index);
app.use('/api/transaction', transaction);
app.use('/api/propertySell', propertySell);
app.use('/api/propertyRent', propertyRent);
app.use('/api/request', request);
app.use('/api/access', access);
app.use('/api/category', category);
app.use('/api/user', user);
app.use('/api/admin', admin);
app.use('/api/roomRent', roomRent);
app.use('/api/roomSell', roomSell);
app.use('/api/testimony', testimony);


app.use(cors());
// let env = 'local_dev'
let env = app.settings.env;
let db_config = {
  local_dev: 'mongodb://localhost/movie',
  development: 'mongodb://admin:admin@ds159112.mlab.com:59112/room360db',
  test: 'mongodb://admin:admin@ds159112.mlab.com:59112/room360dbtes'
}

mongoose.connect(db_config[env],(err,res)=>{
  console.log(db_config[env])
  console.log(err?err:'Berhasil connect ke db '+db_config[env]);
})


app.set('port', port);
console.log('port : '+app.get('port'))
app.listen(app.get('port'), () => {
  console.log('magic happen at port:',app.get('port'))
})
module.exports = app;

@@ -732,16 +732,56 @@
 timony')
+%0Alet upload = require('./routes/upload')
 %0A%0Aapp.us
@@ -851,16 +851,33 @@
 alse%7D));
+%0Aapp.use(cors());
 %0A%0Aapp.us
@@ -1291,26 +1291,24 @@
 imony);%0A
-%0A%0A
 app.use(
 cors());
@@ -1303,42 +1303,53 @@
 use(
-cors());%0A// let env = 'local_dev'%0A
+'/api/upload', upload);%0A%0Alet env = 'test'%0A// 
 let 

change nexmo key