forked from Arjit222830/react-quiz
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
50 lines (40 loc) · 1.5 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
const mongoose = require("mongoose");
const express= require("express");
const app = express();
const path= require('path');
const bodyParser = require("body-parser");
const config= require('config');
const cors= require('cors');
const indexRouter = require('./routes/index');
const questions = require('./routes/questions');
const users = require('./routes/users');
mongoose.connect(config.get('db'),{useNewUrlParser: true,useUnifiedTopology: true})
.then(()=> console.log(`Connected to ${config.get('db')}...`))
.catch(err => console.log(`Could not connect to ${config.get('db')}...`,err));
mongoose.set('useCreateIndex', true);
mongoose.set('useFindAndModify', false);
app.use(express.json());
app.use(cors());
app.use(bodyParser.urlencoded({extended: false}));
app.use('/crackingTheCode', questions);
app.use('/user', users);
require('./prod.js')(app);
app.set("view engine", "pug");
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'));
});
}
else{
app.use(express.static(path.join(__dirname, '/Client/public')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname+'/Client/public/index.html'));
});
}
const port=process.env.PORT || 8080;
console.log(port);
const server=app.listen(port, ()=> console.log(`Listening on port ${port}...`));
var env = process.env.NODE_ENV || 'development';
console.log(env);
module.exports= server;