-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
61 lines (46 loc) · 1.56 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
pry = require('pryjs');
'use strict'
var express = require('express');
var morgan = require('morgan');
var dotenv = require('dotenv').config();
var bodyParser = require('body-parser');
var pg = require('pg');
var session = require('express-session');
var pgSession = require('connect-pg-simple')(session);
var path = require('path');
var methodOverride = require('method-override');
var userRoutes = require( path.join(__dirname, '/routes/users'));
var imageRouter = require( path.join(__dirname, './routes/images'));
var db = require('./db/pg');
var app = express();
var connectionString =process.env.DATABASE_URL;
// var connectionString = "postgres://Viorel:" +process.env.DB_PASSWORD +"@localhost/sessions_users";
// };
// }
app.use(session({
store: new pgSession({
pg : pg,
conString : connectionString,
tableName : 'session'
}),
secret : 'cia',
resave : false,
cookie : { maxAge : 30 * 24 * 60 * 60 * 1000 } // 30 days
}));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(morgan('short'));
app.use(methodOverride('_method'));
app.use(express.static(path.join(__dirname, './public')));
app.set('views', './views');
app.set('view engine', 'ejs');
app.use('/users', userRoutes);
app.use('/images', imageRouter);
app.get('/', function(req, res) {
res.render('home.html.ejs', { user : req.session.user});
});
var port = process.env.PORT || 3000;
var server = app.listen(port);
// var server = app.listen(process.env.PORT || 3000, function() {
// console.log(`Listening on port ${process.env.PORT}`);
// });