How to redirect to agent router from express?

I am adding authentication to my application that uses a reaction router. I configured client routing after the auth-flow example in the reaction router, but using a passport instead of the localstorage that is used in this example. it all works great.

The next step is to protect the routes that I define for expression in server.js. I could send a redirect to /#/login, but that seems fragile. What is the best way to get the server side URL for the login route served by the responder router?

Here's what I have now in mine server.js, which works, but feels fragile:

app.get('/protected',
    // redirecting to #/login seems bad: what if we change hashhistory, etc.
    passport.authenticate('local', { failureRedirect: '/#/login'}),
    function(req, res) {
     res.render('whatever');
    });
+4
source share
1 answer

Configure the route in express to get all routes and routing using a relay, thus ejem. (I hope this can help you)

server.js

import express from 'express'
import path from 'path'

const app = express();

app.use(express.static(__dirname + '/public'));
app.get('*', (req,res) => res.sendFile(path.join(__dirname+'/public/index.html'))).listen(3000,() => console.log('Server on port 3000'))

routes.jsx

import React from 'react'
import ReactDOM from 'react-dom'
import { Router, Route, Link, browserHistory, IndexRedirect } from 'react-router'

import App from '../views/app.jsx'

const Routes = React.createClass({
    render(){
        return(
            <Router history={ browserHistory }>
                <Route path="/" component={App}>
                    <IndexRedirect to="/dashboard"/>
                    <Route path="dashboard" name="Dashboard" component={App} />
                    <Route path="pages" name="Pages" component={Pages} />
                    <Route path="/:Id" component={Page}/>
                    <Route path="/:Id/inbox" name=':ids' component={Inbox}/>
                </Route>
                <Route path="*" component={App}>
                    <IndexRedirect to="/dashboard" />
                </Route>
            </Router>
        );
    }
});
ReactDOM.render(<Routes />, document.getElementById('app'))
+1
source

All Articles