-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (34 loc) · 1.54 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
43
44
45
46
47
const express = require('express')
const morgan = require('morgan')
const mongoose = require('mongoose')
const bodyParser = require('body-parser')
const app = express()
//const redis = require('redis');
//const client = redis.createClient();
var client = require('redis').createClient(process.env.REDIS_URL);
client.on("connect", function () {
console.log("Connected to redis...");
});
//mongoose.connect(`mongodb://${config.mongo.db_connection}/${config.mongo.db_name}`, {useNewUrlParser: true})
//mongoose.connect(process.env.MONGODB_URI , {useNewUrlParser: true});
//mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/bucket', {useNewUrlParser: true});
mongoose.connect(process.env.MONGODB_URI , {useNewUrlParser: true});
mongoose.Promise = global.Promise
app.all("*", function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With,XMLHttpRequest");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS, PATCH");
if (req.method === 'OPTIONS') {
res.send(200);
} else {
next();
}
});
app.use(morgan('dev'))
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use('/api/v1', require('./api/routes/user'));
app.use('/api/v1', require('./api/routes/bucketlist'));
app.use('/api/v1', require('./api/routes/item'));
//app.listen(config.port, () => console.log(`Server started at port: ${config.port}`))
module.exports = app;