-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (34 loc) · 1.17 KB
/
index.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
const express = require('express');
const bodyParser = require('body-parser');
const cors = require("cors");
const cookieParser = require("cookie-parser");
const app = express();
const apiRoutes = require('./routes/api');
const webhookRoutes = require('./routes/webhook');
const mongoose = require('mongoose');
mongoose.connect("mongodb://" + process.env.BDD_USERNAME + ":" + process.env.BDD_PASSWORD + "@" + process.env.BDD_URL, {useNewUrlParser: true, useUnifiedTopology: true}).then(function(){
console.log("connected to database");
}).catch(function(error){
console.log("Error" + error);
});
app.set('port', (process.env.PORT || 5000));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
var corsOption = {
origin: true,
credentials: true
};
app.use(cors(corsOption));
app.use(cookieParser());
app.use('/api', apiRoutes);
app.use('/webhook', webhookRoutes);
app.get('/', function(req, res){
res.status(200).send("Welcome to Bab'isen api and webhook");
});
app.get('/cookie', function(req, res){
res.cookie('test', 'test');
res.send("Hello from cookie route");
});
app.listen(app.get('port'), function(){
console.log("Server is listening");
});