# Redux Tutorial: Adding Custom Middleware

Adding custom middleware is simple. Import* your middlewares and then apply them like so:

* Note that the thunk middleware is prepended to the middlewares passed to applyMiddleware. So no need to import it again.

Client code: src/main.js:


import render, {
  setupReducers,
  applyMiddleware,
  replaceReducers,
} from '@sketchpixy/rubix/lib/node/redux-router';

import promise from 'redux-promise';
import createLogger from 'redux-logger';
const logger = createLogger();

import reducers from './redux/reducers';

setupReducers(reducers);
applyMiddleware(promise, logger);
render(routes);

Server code: server.babel.js:


import routes from './src/routes';
import {
  setupReducers,
  applyMiddleware,
  renderHTMLString,
} from '@sketchpixy/rubix/lib/node/redux-router';
import RubixAssetMiddleware from '@sketchpixy/rubix/lib/node/RubixAssetMiddleware';

import schema from './data/schema.js';

import promise from 'redux-promise';
import createLogger from 'redux-logger';
const logger = createLogger();

import reducers from './src/redux/reducers';
setupReducers(reducers);
applyMiddleware(promise, logger);