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 login = require('./login');
|
||||
const logout = require('./logout');
|
||||
const user = require('./user');
|
||||
const speechPassport = require('speechPassport');
|
||||
const handleSignupRequest = require('./signup');
|
||||
const handleLoginRequest = require('./login');
|
||||
const handleLogoutRequest = require('./logout');
|
||||
const handleUserRequest = require('./user');
|
||||
|
||||
module.exports = {
|
||||
signup,
|
||||
login,
|
||||
logout,
|
||||
user,
|
||||
module.exports = (app) => {
|
||||
app.post('/signup', speechPassport.authenticate('local-signup'), handleSignupRequest);
|
||||
app.post('/login', handleLoginRequest);
|
||||
app.get('/logout', handleLogoutRequest);
|
||||
app.get('/user', handleUserRequest);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const login = (passport) => {
|
||||
return (req, res, next) => {
|
||||
passport.authenticate('local-login', (err, user, info) => {
|
||||
const speechPassport = require('speechPassport');
|
||||
|
||||
const login = (req, res, next) => {
|
||||
speechPassport.authenticate('local-login', (err, user, info) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
@ -22,7 +23,6 @@ const login = (passport) => {
|
|||
});
|
||||
});
|
||||
})(req, res, next);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = login;
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
const logout = () => {
|
||||
return (req, res) => {
|
||||
const logout = (req, res) => {
|
||||
req.logout();
|
||||
res.status(200).json({success: true, message: 'you successfully logged out'});
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = logout;
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
const signup = () => {
|
||||
return (req, res) => {
|
||||
const signup = (req, res) => {
|
||||
res.status(200).json({
|
||||
success : true,
|
||||
channelName : req.user.channelName,
|
||||
channelClaimId: req.user.channelClaimId,
|
||||
shortChannelId: req.user.shortChannelId,
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = signup;
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
const user = () => {
|
||||
return (req, res) => {
|
||||
const user = (req, res) => {
|
||||
if (req.user) {
|
||||
res.status(200).json({success: true, data: req.user});
|
||||
} else {
|
||||
res.status(401).json({success: false, message: 'user is not logged in'});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
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 sendEmbedPage = require('./sendEmbedPage');
|
||||
const handlePageRequest = require('./sendReactApp');
|
||||
const handleEmbedRequest = require('./sendEmbedPage');
|
||||
const redirect = require('./redirect');
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
sendReactApp,
|
||||
sendEmbedPage,
|
||||
redirect,
|
||||
module.exports = (app) => {
|
||||
app.get('/', handlePageRequest);
|
||||
app.get('/login', handlePageRequest);
|
||||
app.get('/about', handlePageRequest);
|
||||
app.get('/trending', redirect('/popular'));
|
||||
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 sendEmbedPage = () => {
|
||||
return ({ params }, res) => {
|
||||
const sendEmbedPage = ({ params }, res) => {
|
||||
const claimId = params.claimId;
|
||||
const name = params.name;
|
||||
// get and render the content
|
||||
res.status(200).render('embed', { layout: 'embed', host, claimId, name });
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = sendEmbedPage;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
const handlePageRender = require('helpers/handlePageRender.jsx');
|
||||
|
||||
const sendReactApp = () => {
|
||||
return (req, res) => {
|
||||
const sendReactApp = (req, res) => {
|
||||
handlePageRender(req, res);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = sendReactApp;
|
||||
|
|
|
@ -4,11 +4,8 @@ const bodyParser = require('body-parser');
|
|||
const expressHandlebars = require('express-handlebars');
|
||||
const Handlebars = require('handlebars');
|
||||
const helmet = require('helmet');
|
||||
const passport = require('passport');
|
||||
const { serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js');
|
||||
const cookieSession = require('cookie-session');
|
||||
const http = require('http');
|
||||
// logging dependencies
|
||||
const logger = require('winston');
|
||||
|
||||
function Server () {
|
||||
|
@ -41,20 +38,15 @@ function Server () {
|
|||
});
|
||||
|
||||
// configure passport
|
||||
passport.serializeUser(serializeSpeechUser);
|
||||
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);
|
||||
const speechPassport = require('speechPassport');
|
||||
// initialize passport
|
||||
app.use(cookieSession({
|
||||
name : 'session',
|
||||
keys : [this.sessionKey],
|
||||
maxAge: 24 * 60 * 60 * 1000, // i.e. 24 hours
|
||||
}));
|
||||
app.use(passport.initialize());
|
||||
app.use(passport.session());
|
||||
app.use(speechPassport.initialize());
|
||||
app.use(speechPassport.session());
|
||||
|
||||
// configure handlebars & register it with express app
|
||||
const hbs = expressHandlebars.create({
|
||||
|
@ -80,7 +72,7 @@ function Server () {
|
|||
this.server = http.Server(this.app);
|
||||
};
|
||||
this.start = () => {
|
||||
const db = require('./models/index');
|
||||
const db = require('./models/');
|
||||
// sync sequelize
|
||||
db.sequelize.sync()
|
||||
// start the server
|
||||
|
|
|
@ -11,7 +11,7 @@ const logger = require('./config/loggerConfig.js');
|
|||
const mysql = require('./config/mysqlConfig');
|
||||
const site = require('./config/siteConfig');
|
||||
const slack = require('./config/slackConfig.js');
|
||||
const passport = require('./server/passport/');
|
||||
const passport = require('./server/speechPassport/');
|
||||
const models = require('./server/models/');
|
||||
|
||||
const exports = {
|
||||
|
|
Loading…
Reference in a new issue