Skip to content

Instantly share code, notes, and snippets.

@slyder
Created May 19, 2015 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slyder/a66848456b99987ade79 to your computer and use it in GitHub Desktop.
Save slyder/a66848456b99987ade79 to your computer and use it in GitHub Desktop.
// express method
app.use(async function (req, res, next) {
try {
let flux = new Flux();
var {HandlerComponent, state} = await AuxService.runReactRouter(reactRoutes, req.url);
await AuxService.performRouteHandlerStaticMethod(state.routes, 'routerWillRun', {state, flux, req});
...
}
...
}
// app component
class App extends React.Component {
static async routerWillRun({flux, state, req}) {
await flux.getActions('session').getSession(req);
}
// rendering ...
}
// session actions
class SessionActions extends AppActions {
getSession(req) {
// using req object here to pass cookies
return this.apiGet('/api/session/get', req);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment