-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
105 lines (89 loc) · 3 KB
/
index.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var express = require('express');
var app = express();
var db = require('./controllers/playlists.js');
var flash = require("express-flash");
var passport = require("passport");
var LocalStrategy = require('passport-local').Strategy;
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var errorHandler = require('errorhandler');
var session = require('express-session');
var app = express();
var pg = require('pg');
var secrets = require('./secrets');
var passportConf = require('./config/passport');
var auth = require('./controllers/auth');
var pgSession = require('connect-pg-simple')(session);
app.set('port', (process.env.PORT || 5000));
// make express look in the public directory for assets (css/js/img)
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(session({
resave: true,
saveUninitialized: true,
store: new pgSession({
pg : pg, // Use global pg-module
conString : secrets.db,
tableName : 'session'
}),
secret: secrets.sessionSecret,
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use(function(request, response, next) {
response.locals.user = request.user;
next();
});
// might have to change these setting to match backbone
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.get('/', function(request, response) {
if (!request.user) {
response.redirect('/login');
} else {
response.render('pages/index', {index: true, profile: false});
}
});
/*** LOGIN STUFF ***/
app.get('/login',auth.getLogin);
app.post('/login', auth.postLogin);
app.get('/signup', auth.getSignup);
app.post('/signup', auth.postSignup);
app.get('/logout', auth.logout);
app.get('/db/addRecord', function(req,res){
db.addRecord(req,res);
});
app.get('/db/createTable', function(req,res){
db.createTable(req,res);
});
app.get('/db/dropTable', function(req,res){
db.dropTable(req,res);
});
app.get('/profile/', auth.getUser);
app.get('/profile/:username', auth.getUser);
app.get('/generate', db.generate);
app.get('/playlists', db.fetch);
app.post('/save', db.save);
app.post('/delete/:playlistname', db.deletePlaylist);
app.get('/playlists/:username/:playlistname', db.getSimilarPlaylists);
app.get('/users/:username', db.getSimilarUsers);
app.post('/edit', db.editPlaylistName);
/** FOLLOWING **/
app.get('/follow/:username', auth.addFollower);
app.get('/followers/:username', auth.getFollowers);
app.get('/following', auth.getFollowees);
app.get('/following/:username', auth.getFollowees);
/*****/
app.get('/graph/:username/:playlistname', function(request, response) {
response.render('pages/graph', {username: request.params.username});
});
app.get('/usergraph/:username', function(request, response) {
response.render('pages/usergraph');
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
exports.app = app;