question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I apply middlewares into the project

See original GitHub issue

Hello there!

Love this boilerplate and look forward to using it! But I am having trouble figuring out how to implement middleware.

I am trying to implement something like this.

const store = createReduxStore(
    makeRootReducer(),
    initialState,
    composeEnhancers(
      reactReduxFirebase(firebaseConfig, reduxFirebaseConfig),
      applyMiddleware(
        RavenMiddleware(),
        ...OtherMiddleware
      ),
      ...enhancers
    )
);

Where would be the best place to add middleware?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tirthbodawalacommented, Feb 27, 2018

I see what you are trying to do here… let me update the code and implement the feature for this today.

1reaction
tirthbodawalacommented, Mar 1, 2018

Hello @IrvingAxelB & @MikeShobe

For doing the above you need to update client.js and server.js as below:

src/client.js

// ... previous code
export const reduxEnahancers = [
  reactReduxFirebase(firebaseConfig, reduxFirebaseConfig), 
  ...enhancers
];
export const reduxMiddlewares = [
  RavenMiddleware(),
   ...OtherMiddleware
];

// ... other code

src/server.js

// ... previous code
app.use((req, res, next) => {
  res.locals.reduxInitialState = {
    // some initial state
  };
  // your app reducers
  res.locals.reduxReducers = appReducers;
  
  res.locals.reduxEnhancers = [
    reactReduxFirebase(firebaseConfig, reduxFirebaseConfig), 
    ...enhancers
  ]
  res.locals.reduxMiddlewares = [
    RavenMiddleware(),
    ...OtherMiddleware
  ];
  
  next();
});
// ... other code
Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing middleware for use in Express apps
Middleware functions are functions that have access to the request object ( req ), the response object ( res ), and the next...
Read more >
applyMiddleware - Redux
The most common use case for middleware is to support asynchronous actions without much boilerplate code or a dependency on a library like ......
Read more >
Complete Guide to Express Middleware - Reflectoring
Middleware functions are attached to one or more route handlers in an Express application and execute in sequence from the time an HTTP...
Read more >
Add custom middleware in ASP.NET Core application
For this, right click on the project or folder where you want to create middleware class and select Add -> New Item. This...
Read more >
How To Use And Write Express Middleware
To get started working with a Node.js project you will need to run npm init -y . This will create a basic package.json...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found