-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
63 lines (57 loc) · 2.13 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var mongo = require('mongodb');
var bodyParser = require('body-parser');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var app = express();
var dbConn = mongo.MongoClient.connect('mongodb://localhost:27017');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.resolve(__dirname, 'public')));
app.post('/post-submit', function (req, res) {
dbConn.then(function(db) {
var dbo = db.db("bcclub");
delete req.body._id; // for safety reasons
dbo.collection('userData').insertOne(req.body);
});
res.send('Data received:\n' + JSON.stringify(req.body));
console.log("1 Data inserted");
});
app.post('/post-subscribe', function (req, res) {
dbConn.then(function(db) {
var dbo = db.db("bcclub");
delete req.body._id; // for safety reasons
dbo.collection('subscriberData').insertOne(req.body);
});
res.send('Data received:\n' + JSON.stringify(req.body));
console.log("1 Data inserted");
});
app.post('/post-mail', function (req, res) {
dbConn.then(function(db) {
var dbo = db.db("bcclub");
delete req.body._id; // for safety reasons
dbo.collection('mailData').insertOne(req.body);
});
res.send('Data received:\n' + JSON.stringify(req.body));
console.log("1 Data inserted");
});
app.post('/post-conference', function (req, res) {
dbConn.then(function(db) {
var dbo = db.db("bcclub");
delete req.body._id; // for safety reasons
dbo.collection('conferenceData').insertOne(req.body);
});
res.send('Data received:\n' + JSON.stringify(req.body));
console.log("1 Data inserted");
});
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// app.listen(process.env.PORT || 3000, process.env.IP || '0.0.0.0' );
app.use('/', indexRouter);
app.use('/users', usersRouter);
module.exports = app;