-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
60 lines (46 loc) · 1.6 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
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var session = require('express-session');
var app = express();
var methodOverride = require('method-override');
//environment variables
var port = process.env.PORT || 3000;
var mongoDBURI = process.env.MONGODB_URI || 'mongodb://localhost:27017/yarn';
//middleware+++++++++++++++++++++++++++++++++++++
app.use(methodOverride('_method'));
app.use(bodyParser.urlencoded({extended: false}));
app.use(session({
secret: "peanutbutterjellytime",
resave: false,
saveUninitialized: false
}));
app.use(express.static('public'));
//sessions controller middleware
var sessionsController = require('./controllers/sessions.js');
app.use('/sessions', sessionsController);
//users controller middleware
var usersController = require('./controllers/users.js');
app.use('/users', usersController);
//stories controller middleware
var storiesController = require('./controllers/stories.js');
app.use('/stories', storiesController);
//--------------------------------ROUTES---------------------------------
app.get('/', function(req, res){
res.render('index.ejs', {
currentUser: req.session.currentuser
});
});
app.get('/about', function(req, res){
res.render('about.ejs',{
currentUser: req.session.currentuser
});
});
//connections++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
app.listen(port, function(){
console.log("listening on port " + port);
});
mongoose.connect(mongoDBURI);
mongoose.connection.once('open', function(){
console.log('connected to mongo!');
});