我一直在使用nextjs / reduxSaga / expressJs创建一个简单的待办事项应用程序。使用Node.js服务器渲染应用程序时出现问题,我的Redux工具无法正常工作,但操作正常进行。
我说“当我使用我的nodejs服务器时”是因为使用nextjs提供的测试服务器时,一切似乎都工作正常。 商店代码:
import {createStore, applyMiddleware, compose} from 'redux'
import createSagaMiddleware from 'redux-saga'
import taskReducer from './reducers/tasks'
import {watchFetchTask} from './sagas'
const sagaMiddleware = createSagaMiddleware()
const bindMiddleware = (middleware) => {
if (process.env.NODE_ENV !== 'production') {
const { composeWithDevTools } = require('redux-devtools-extension')
return composeWithDevTools(applyMiddleware(...middleware))
}
return applyMiddleware(...middleware)
}
function configureStore () {
const store = createStore(
taskReducer,
bindMiddleware([sagaMiddleware])
)
store.runSagaTask = () => {
store.sagaTask = sagaMiddleware.run(watchFetchTask)
}
store.runSagaTask()
return store
}
export default configureStore
Nodejs服务代码:
exports.index = (req, res) => {
handle(req, res)
}
句柄是:
const dev = process.env.NODE_ENV !== 'production'
const nextapp = next({dev})
const handle = nextapp.getRequestHandler()
由于在服务器上触发了bindMiddleware,因此我看不到该怎么办。我如何使其与我的nodejs服务器一起工作?