Passing param to custom middleware

Passing param to custom middleware

By : Meijupe
Date : November 14 2020, 04:51 PM
I think the issue was by ths following , The preferred way to pass arguments/configuration options to a middleware is by returning a function from the middleware that captures the arguments using a closure.
code :
 module.exports = {
      auth: function (client) {
        return function (req, res, next) {
          //use client
module.exports = function(app,client) {
  router.get('/', mw.auth(client), function (req, res) {

var JsonRpcServer = require('./rpc-server');

module.exports = function jsonrpc (methods) {
    var jsonRpcServer = new JsonRpcServer(methods);
    return function(req, res, next) {
        var rpcResponse,
        rpcRequest = req.body,
        contentType = req.headers['content-type'];

        if(req.method === 'POST' && ~contentType.indexOf('application/json')) {
            rpcResponse = jsonRpcServer._handleRpc(rpcRequest);
            if(Array.isArray(rpcResponse) && rpcResponse.length || rpcResponse.id) {
                rpcResponse = JSON.stringify(rpcResponse);
                res.writeHead(200, {
                    'Content-Length': String(Buffer.byteLength(rpcResponse)),
                    'Content-Type': contentType
            else {
        else next();

Share : facebook icon twitter icon
Using *_path(:param => @param) in link_to is not passing the param to controller

Using *_path(:param => @param) in link_to is not passing the param to controller

By : Mars Euuh
Date : March 29 2020, 07:55 AM
Custom Post action not passing param

Custom Post action not passing param

By : user7900541
Date : March 29 2020, 07:55 AM
hope this fix your issue Define your routes using resources and this should be easier:
code :
resources :properties do 
  member do
    post :update_promo_image
form_for(@property, :html => {:id => "promo-upload-form"} , :url => update_promo_image_property_url(@property)) do |form|
  form.input :field1
Express v4: How do I run route-specific middleware before param middleware?

Express v4: How do I run route-specific middleware before param middleware?

By : Ксенія Іванченко
Date : March 29 2020, 07:55 AM
Hope that helps I'm by no means an expert at regular expressions, but you can use regular expressions to match routes. This would work for your specific use case, although there may be a better way of doing it.
code :
router.use(/^\/[^\/]*$/, function(req, res, next) {

How do I allow the skip() method for Buffalo (gobuffalo) middleware when I'm passing the middleware config?

How do I allow the skip() method for Buffalo (gobuffalo) middleware when I'm passing the middleware config?

By : Gerry Li
Date : March 29 2020, 07:55 AM
it fixes the issue You need to staisfy required func but your require additional parameters which can't be passed. You probably can change how you approach this by making your myConfig as reciever of myMiddlewareFunc, by this I mean:
code :
type myConfig struct {
    value string

func (config *myConfig) myMiddlewareFunc() buffalo.MiddlewareFunc {
    return func(next buffalo.Handler) buffalo.Handler {
        return func(c buffalo.Context) error {
            c.Logger().Info("Test ", config.value)

            return next(c)

func App() *buffalo.App {
    if app == nil {
        app = buffalo.New(buffalo.Options{
            Env:         ENV,
            SessionName: "_myapp_session",
        // Automatically redirect to SSL
            SSLRedirect:     ENV == "production",
            SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},

        if ENV == "development" {

        // Protect against CSRF attacks. https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)
        // Remove to disable this.

        // Wraps each request in a transaction.
        //  c.Value("tx").(*pop.PopTransaction)
        // Remove to disable this.

        // Setup and use translations:
        var err error
        if T, err = i18n.New(packr.NewBox("../locales"), "en-US"); err != nil {

        c := &myConfig{
            value: "test value",
        app.Middleware.Skip(c.myMiddlewareFunc(), TestHandler)

        app.GET("/", HomeHandler)
        app.GET("/test", TestHandler)

        app.ServeFiles("/assets", assetsBox)

    return app
Express v4 custom Joi middleware not passing Request, Response, Next

Express v4 custom Joi middleware not passing Request, Response, Next

By : user3656971
Date : March 29 2020, 07:55 AM
it should still fix some issue I'm trying to create a custom middleware function to use with Joi that I will place on my routes that I can pass a Joi schema to validate. , This is my middleware Joi validator
In my route
code :
import express from 'express'
import checkJoi from '../middlewares/check-joi'
import Joi from '@hapi/joi'

const router = new express.Router()

const schemaIndex = Joi.object({
  addressId: Joi.number().required(),
  products: Joi.array().items(
      id: Joi.number().required(),
      quantity: Joi.number().required()

router.post('/', checkJoi(schemaIndex), myController.requestUser)

export default router
export default (schema) => {
  return (req, res, next) => {
    const { error } = schema.validate(req.body)
    const valid = error == null
    if (valid) {
    } else {
      const { details } = error
      const errorsDetail = details.map(i => i.message)
        status: false,
        error: errorsDetail

Related Posts Related Posts :
  • how we will know on the server side if the peer still connected using Nodejs WebRTC
  • Docker Remote API & Binds
  • Serving multiple node apps with nginx on same domain
  • Waiting for user to enter input in Node.js
  • How to get instant changes in background from private api in mobile app?
  • Grunt.js: Fire livereload as soon a files are modified, before task completes
  • How to remove port number from appear in the url for node js application?
  • How to ignore libraries in browserify programmatic api
  • Node/Express/Jade style guides?
  • how do I return data from a node.js request call? (undefined is not a function)
  • res.sendfile() doesn't serve javascripts well
  • File path completion relative to the current file directory
  • Tuning node-mongodb-native connection pool size
  • Express Socket.io example server not working
  • node js can't install right on my Ubuntu computer
  • How can i do an "or" query in a Model.find on Sails?
  • Confused in starting a project in node.js with npm install
  • unit testing express route with async callback
  • Mongoose sum operation in collection
  • document save function not working in mongoose
  • Why is the zlib inflate function is not working in correct order in node.js?
  • Nested if inside each (Handlebars template in Express app)
  • How does the cookie-session middleware work in expressjs?
  • grunt-processhtml remove not working when specifying a target
  • Error: CERT_HAS_EXPIRED in Node.js request module (macu vs facebook)
  • Async web requests are making 'socket hangup' in node.js
  • ExpressJS: Middleware control flow for Router.param() & Router.use()
  • Glob recursive/zero or more directories, excluding directories
  • node.js v0.11.14 as service with --harmony
  • Running npm install from Sublime Text 2 doesn't work
  • update on a subdoc with mongoose
  • NodeJS Aerospike UDF execute memory leak
  • Alternative to path module that always uses forward-slashes?
  • How do you stream a csv file into a node web app?
  • How to modularize routing with Node.js Express
  • NodeJS - Modularising SQLite3
  • MongoDB / Node: Incorrect Arguments
  • How to use Aggregate in mongoose
  • How to generate multiple reports with mocha?
  • AWS Lambda making video thumbnails
  • MEAN stack on Ubuntu 14.04 suddenly stopped working
  • node.js/express/mongoose noob issue
  • Nodejs ssh convert output byte stream to a sliceable string
  • different behavior of process.argv
  • How to expose the Application model's register method
  • How to install FFMPEG on Node/Meteor server?
  • How Can I Use vhost to Redirect a Sub-Domain to an ExpressJS Route?
  • Gmail API not respecting UTF encoding in subject
  • installing Node modules on Docker: why are they disappearing?
  • How do I set up Node/Express to act as a STUN server?
  • What is the Linear Execution Model in Meteor?
  • connect-redis and express-session results in req.session undefined
  • Application Error Heroku - Problems with Deployment
  • How to pass node v8 args and script args to pm2?
  • Can it be necessary to require a module (child_process in this case) more than once?
  • Too many bad command: outbound emails with Haraka
  • what does require("child_process") actually do?
  • How can I list all my Amazon EC2 instances using Node.js in AWS Lambda?
  • How do I debug "Error: spawn ENOENT" on node.js?
  • Proper way to combine route and api auth using loopback.js
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org