fixed auth, fallback, and pages routes
This commit is contained in:
parent
9523890b65
commit
c67a25ca2c
15 changed files with 81 additions and 84 deletions
|
@ -1,11 +1,12 @@
|
||||||
const signup = require('./signup');
|
const speechPassport = require('speechPassport');
|
||||||
const login = require('./login');
|
const handleSignupRequest = require('./signup');
|
||||||
const logout = require('./logout');
|
const handleLoginRequest = require('./login');
|
||||||
const user = require('./user');
|
const handleLogoutRequest = require('./logout');
|
||||||
|
const handleUserRequest = require('./user');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = (app) => {
|
||||||
signup,
|
app.post('/signup', speechPassport.authenticate('local-signup'), handleSignupRequest);
|
||||||
login,
|
app.post('/login', handleLoginRequest);
|
||||||
logout,
|
app.get('/logout', handleLogoutRequest);
|
||||||
user,
|
app.get('/user', handleUserRequest);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
const login = (passport) => {
|
const speechPassport = require('speechPassport');
|
||||||
return (req, res, next) => {
|
|
||||||
passport.authenticate('local-login', (err, user, info) => {
|
const login = (req, res, next) => {
|
||||||
|
speechPassport.authenticate('local-login', (err, user, info) => {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
if (!user) {
|
||||||
|
return res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
message: info.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
req.logIn(user, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
if (!user) {
|
return res.status(200).json({
|
||||||
return res.status(400).json({
|
success : true,
|
||||||
success: false,
|
channelName : req.user.channelName,
|
||||||
message: info.message,
|
channelClaimId: req.user.channelClaimId,
|
||||||
});
|
shortChannelId: req.user.shortChannelId,
|
||||||
}
|
|
||||||
req.logIn(user, (err) => {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
return res.status(200).json({
|
|
||||||
success : true,
|
|
||||||
channelName : req.user.channelName,
|
|
||||||
channelClaimId: req.user.channelClaimId,
|
|
||||||
shortChannelId: req.user.shortChannelId,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})(req, res, next);
|
});
|
||||||
};
|
})(req, res, next);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = login;
|
module.exports = login;
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
const logout = () => {
|
const logout = (req, res) => {
|
||||||
return (req, res) => {
|
req.logout();
|
||||||
req.logout();
|
res.status(200).json({success: true, message: 'you successfully logged out'});
|
||||||
res.status(200).json({success: true, message: 'you successfully logged out'});
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = logout;
|
module.exports = logout;
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
const signup = () => {
|
const signup = (req, res) => {
|
||||||
return (req, res) => {
|
res.status(200).json({
|
||||||
res.status(200).json({
|
success : true,
|
||||||
success : true,
|
channelName : req.user.channelName,
|
||||||
channelName : req.user.channelName,
|
channelClaimId: req.user.channelClaimId,
|
||||||
channelClaimId: req.user.channelClaimId,
|
shortChannelId: req.user.shortChannelId,
|
||||||
shortChannelId: req.user.shortChannelId,
|
});
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = signup;
|
module.exports = signup;
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
const user = () => {
|
const user = (req, res) => {
|
||||||
return (req, res) => {
|
if (req.user) {
|
||||||
if (req.user) {
|
res.status(200).json({success: true, data: req.user});
|
||||||
res.status(200).json({success: true, data: req.user});
|
} else {
|
||||||
} else {
|
res.status(401).json({success: false, message: 'user is not logged in'});
|
||||||
res.status(401).json({success: false, message: 'user is not logged in'});
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = user;
|
module.exports = user;
|
||||||
|
|
5
server/routes/fallback/index.js
Normal file
5
server/routes/fallback/index.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
const handlePageRequest = require('./sendReactApp');
|
||||||
|
|
||||||
|
module.exports = (app) => {
|
||||||
|
app.get('*', handlePageRequest);
|
||||||
|
};
|
7
server/routes/fallback/sendReactApp.js
Normal file
7
server/routes/fallback/sendReactApp.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
const handlePageRender = require('helpers/handlePageRender.jsx');
|
||||||
|
|
||||||
|
const sendReactApp = (req, res) => {
|
||||||
|
handlePageRender(req, res);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = sendReactApp;
|
|
@ -1,11 +1,13 @@
|
||||||
const sendReactApp = require('./sendReactApp');
|
const handlePageRequest = require('./sendReactApp');
|
||||||
const sendEmbedPage = require('./sendEmbedPage');
|
const handleEmbedRequest = require('./sendEmbedPage');
|
||||||
const redirect = require('./redirect');
|
const redirect = require('./redirect');
|
||||||
|
|
||||||
|
module.exports = (app) => {
|
||||||
|
app.get('/', handlePageRequest);
|
||||||
module.exports = {
|
app.get('/login', handlePageRequest);
|
||||||
sendReactApp,
|
app.get('/about', handlePageRequest);
|
||||||
sendEmbedPage,
|
app.get('/trending', redirect('/popular'));
|
||||||
redirect,
|
app.get('/popular', handlePageRequest);
|
||||||
|
app.get('/new', handlePageRequest);
|
||||||
|
app.get('/embed/:claimId/:name', handleEmbedRequest); // route to send embedable video player (for twitter)
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
const { details: { host } } = require('siteConfig.js');
|
const { details: { host } } = require('siteConfig.js');
|
||||||
|
|
||||||
const sendEmbedPage = () => {
|
const sendEmbedPage = ({ params }, res) => {
|
||||||
return ({ params }, res) => {
|
const claimId = params.claimId;
|
||||||
const claimId = params.claimId;
|
const name = params.name;
|
||||||
const name = params.name;
|
// get and render the content
|
||||||
// get and render the content
|
res.status(200).render('embed', { layout: 'embed', host, claimId, name });
|
||||||
res.status(200).render('embed', { layout: 'embed', host, claimId, name });
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = sendEmbedPage;
|
module.exports = sendEmbedPage;
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
const handlePageRender = require('helpers/handlePageRender.jsx');
|
const handlePageRender = require('helpers/handlePageRender.jsx');
|
||||||
|
|
||||||
const sendReactApp = () => {
|
const sendReactApp = (req, res) => {
|
||||||
return (req, res) => {
|
handlePageRender(req, res);
|
||||||
handlePageRender(req, res);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = sendReactApp;
|
module.exports = sendReactApp;
|
||||||
|
|
|
@ -4,11 +4,8 @@ const bodyParser = require('body-parser');
|
||||||
const expressHandlebars = require('express-handlebars');
|
const expressHandlebars = require('express-handlebars');
|
||||||
const Handlebars = require('handlebars');
|
const Handlebars = require('handlebars');
|
||||||
const helmet = require('helmet');
|
const helmet = require('helmet');
|
||||||
const passport = require('passport');
|
|
||||||
const { serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js');
|
|
||||||
const cookieSession = require('cookie-session');
|
const cookieSession = require('cookie-session');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
// logging dependencies
|
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
|
|
||||||
function Server () {
|
function Server () {
|
||||||
|
@ -41,20 +38,15 @@ function Server () {
|
||||||
});
|
});
|
||||||
|
|
||||||
// configure passport
|
// configure passport
|
||||||
passport.serializeUser(serializeSpeechUser);
|
const speechPassport = require('speechPassport');
|
||||||
passport.deserializeUser(deserializeSpeechUser);
|
|
||||||
const localSignupStrategy = require('./passport/local-signup.js');
|
|
||||||
const localLoginStrategy = require('./passport/local-login.js');
|
|
||||||
passport.use('local-signup', localSignupStrategy);
|
|
||||||
passport.use('local-login', localLoginStrategy);
|
|
||||||
// initialize passport
|
// initialize passport
|
||||||
app.use(cookieSession({
|
app.use(cookieSession({
|
||||||
name : 'session',
|
name : 'session',
|
||||||
keys : [this.sessionKey],
|
keys : [this.sessionKey],
|
||||||
maxAge: 24 * 60 * 60 * 1000, // i.e. 24 hours
|
maxAge: 24 * 60 * 60 * 1000, // i.e. 24 hours
|
||||||
}));
|
}));
|
||||||
app.use(passport.initialize());
|
app.use(speechPassport.initialize());
|
||||||
app.use(passport.session());
|
app.use(speechPassport.session());
|
||||||
|
|
||||||
// configure handlebars & register it with express app
|
// configure handlebars & register it with express app
|
||||||
const hbs = expressHandlebars.create({
|
const hbs = expressHandlebars.create({
|
||||||
|
@ -80,7 +72,7 @@ function Server () {
|
||||||
this.server = http.Server(this.app);
|
this.server = http.Server(this.app);
|
||||||
};
|
};
|
||||||
this.start = () => {
|
this.start = () => {
|
||||||
const db = require('./models/index');
|
const db = require('./models/');
|
||||||
// sync sequelize
|
// sync sequelize
|
||||||
db.sequelize.sync()
|
db.sequelize.sync()
|
||||||
// start the server
|
// start the server
|
||||||
|
|
|
@ -11,7 +11,7 @@ const logger = require('./config/loggerConfig.js');
|
||||||
const mysql = require('./config/mysqlConfig');
|
const mysql = require('./config/mysqlConfig');
|
||||||
const site = require('./config/siteConfig');
|
const site = require('./config/siteConfig');
|
||||||
const slack = require('./config/slackConfig.js');
|
const slack = require('./config/slackConfig.js');
|
||||||
const passport = require('./server/passport/');
|
const passport = require('./server/speechPassport/');
|
||||||
const models = require('./server/models/');
|
const models = require('./server/models/');
|
||||||
|
|
||||||
const exports = {
|
const exports = {
|
||||||
|
|
Loading…
Reference in a new issue