Comments (10)
I currently use koa under universal-redux, simply wrapping the express middleware; https://github.com/vkurchatkin/koa-connect
I'm having a look at making the renderer more dynamic, so it could work with either express or koa middleware. This part is tripping me up though;
if (config.redux.middleware) {
const customMiddleware = require(path.resolve(config.redux.middleware)).default;
each(customMiddleware, (customMiddlewareToAdd) => {
if (typeof customMiddlewareToAdd === 'function') {
middleware.push(customMiddlewareToAdd(req, res));
}
});
}
The custom middleware I've worked with so far were not dependent on the express req, res objects, but I can imagine others might use it in some other way. Can you tell me what the intention is for passing the req and res into the custom middleware? Is there an example?
from universal-redux.
@bartolkaruza I believe you are correct that this is unconventional, and was related to migrating the ApiClient.js from the react-redux-universal-hot-example project. That library needed access to the request object in order to retrieve and set cookies for authentication purposes. The modified version is in use in the JWT example here: https://github.com/bdefore/react-redux-universal-hot-example/blob/react-router-2/src/redux/middleware/fetcher.js
That said, I think it's more appropriate to follow Redux middleware conventions, and if need be, find another way to implement that fetcher. Would you agree that the appropriate way to assign the middleware should be without checking for function, nor executing it? Like so:
const middleware = [];
if (config.redux.middleware) {
const customMiddleware = require(path.resolve(config.redux.middleware)).default;
each(customMiddleware, (customMiddlewareToAdd) => {
middleware.push(customMiddlewareToAdd);
});
}
Hit me up on Reactiflux if you'd like to chat more about it.
from universal-redux.
You'll also want to similarly modify client.js
. In fact now that req
and res
need not be applied, these should be pulled into a helper.
from universal-redux.
Well, hey, even more terse: const middleware = config.redux.middleware ? require(path.resolve(config.redux.middleware)).default : [];
from universal-redux.
@bartolkaruza I've released 3.0.0-rc3 based on these changes
from universal-redux.
I've made a first attempt, untested;
bartolkaruza@ec50f67
I'm curious what you think of this approach.
from universal-redux.
@bartolkaruza that actually looks about like what i was thinking too. i like how you've managed to contain the original logic into dynamicMiddleware
. would be great to see this in a PR with an addition to examples
that's working with koa.
one thing I'm wondering: would it be possible to glean whether the server is koa or express based on the incoming arguments rather than require configuration? does the response object already come with the identifier by the time it hits this middleware?
from universal-redux.
@bartolkaruza ping!
from universal-redux.
@bdefore I saw you merged the PR. Great stuff. Close this issue?
from universal-redux.
@bartolkaruza yup, thanks!
from universal-redux.
Related Issues (20)
- onEnter can't redirect HOT 1
- How to access external server api (rails or laravel ... etc) from universal-redux?
- [webpack-isomorphic-tools] (waiting for the first Webpack build to finish)
- how the server side API requests handle the jwt token?
- Move to redux-connect HOT 1
- Help required?
- Question about waiting for Server Requests HOT 1
- Question about โAdd routes, reducer and rootClientComponent aliases so that client has access to themโ HOT 5
- Setting scroll behavior for the router
- SVG Loading Configuration
- Different CSS idents cause server render to be discarded HOT 1
- Using npm dependencies listed in Universal-redux on the project level HOT 3
- [webpack-isomorphic-tools] asset not found HOT 9
- Question: how to alter the JS loader HOT 4
- Passing Express request headers to Html component?
- @@router/UPDATE_LOCATION fired after first dispatched action HOT 3
- Server-side React render was discarded HOT 5
- Use redux-devtools-extension HOT 1
- integrate HappyPack
- should user other way to compile es6-7 with babel
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from universal-redux.