-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
74 lines (58 loc) · 1.82 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
66
67
68
69
70
71
72
73
74
//___________________
//Dependencies
//___________________
const express = require('express');
const mongoose = require('mongoose');
const session = require('express-session');
require('dotenv').config();
const app = express ();
const db = mongoose.connection;
const key = process.env.GOOGLE_DEV_KEY
// PORT
const PORT = process.env.PORT || 3000;
// DATABASE
const PROJECT3_DB = process.env.PROJECT3_DB;
// Fix Depreciation Warnings from Mongoose*
// May or may not need these depending on your Mongoose version
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);
// Connect to Mongo
mongoose.connect(PROJECT3_DB , { useNewUrlParser: true});
// Error / success
db.on('error', (err) => console.log(err.message + ' is Mongod not running?'));
db.on('connected', () => console.log('mongo connected: ', PROJECT3_DB));
db.on('disconnected', () => console.log('mongo disconnected'));
app.use(express.json());
app.use(express.static('public'));
app.use(session({
secret: process.env.SECRET,
resave: false,
saveUninitialized: false
}));
//ENV
app.get("/config", (req, res) => {
res.json(key);
})
// AUTH ROUTE
app.get('/app', (req, res)=>{
if(req.session.currentUser){
// console.log(req.session.currentUser);
res.json(req.session.currentUser)
} else {
res.status(401).json({
status: 401,
message: 'not logged in'
})
}
})
// CONTROLLERS
const userController = require('./controllers/users.js')
app.use('/users', userController);
const sessionsController = require('./controllers/sessions.js');
app.use('/sessions', sessionsController);
const firesController = require('./controllers/fires.js');
app.use('/fires', firesController);
//___________________
//Listener
//___________________
app.listen(PORT, () => console.log( 'Listening on port:', PORT));