-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
65 lines (56 loc) · 1.76 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
58
59
60
61
62
63
64
65
const express = require('express');
const cors = require('cors');
const path = require('path');
const mongoose = require('mongoose');
const passport = require("passport");
require('dotenv').config();
const app = express();
const port = process.env.PORT || 4000;
app.use(cors());
app.use(express.json());
const uri = process.env.ATLAS_URI;
mongoose.connect(uri, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true }
);
const connection = mongoose.connection;
connection.once('open', () => {
console.log("MongoDB connection established");
})
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'client', 'build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '/client/build/index.html'));
})
}
// Passport middleware
app.use(passport.initialize());
// Passport config
require("./config/passport")(passport);
const usersRouter = require('./routes/users');
const learnPostsRouter = require('./routes/learnPost');
const chatMessageRouter = require('./routes/chatMessage');
app.use('/users', usersRouter);
app.use('/learnPosts', learnPostsRouter);
app.use('/chat', chatMessageRouter);
app.listen(port, () => {
console.log(`Server running on port: ${port}`);
});
//
// let PythonShell = require('python-shell');
//
// // Python function is executed whenever url is of the form localhost:3000/name
// app.get('/search', callGetAPIResults);
//
// function callGetAPIResults(req, res) {
// let options = {
// args:
// [
// req.query.re, // starting funds
// req.query.size, // (initial) wager size
// ]
// }
//
// PythonShell.run('./search.py', options, function (err, data) {
// if (err) res.send(err);
// res.send(data.toString())
// });
// }