Giter Club home page Giter Club logo

Comments (11)

pedrozero-com avatar pedrozero-com commented on June 23, 2024 3

I ran into this same issue. Solved by passing the request parameter {connection: {}}. E.g.:

app.runMiddleware('/handler', {connection: {}}, function(code, data) {
  console.log(code, data);
  process.exit();
})

from node-run-middleware.

WeishengChang avatar WeishengChang commented on June 23, 2024 3

I solved it by passing original_req parameter:

app.runMiddleware('/another-route', {original_req: req}, function(err, data) {
  ...
});

from node-run-middleware.

borisovg avatar borisovg commented on June 23, 2024

Looks like adding any sort of middleware is enough to break it :(

var express = require('express');
var runMiddleware = require('run-middleware');

var app = express();

app.use(function (req, res, next) {
    console.log({uri: req.originalUrl, method: req.method, ip: req.ip}, 'Request');
    next();
});

app.get('/foo', function (req, res) {
    res.json({result: 'OK'});
});

runMiddleware(app);

app.runMiddleware('/foo', function (code, body) {
    console.log('CODE:', code);
    console.log('BODY:', body);
});

results in

_stream_readable.js:633
  if (state.pipesCount === 0)
           ^

TypeError: Cannot read property 'pipesCount' of undefined
    at IncomingMessage.Readable.unpipe (_stream_readable.js:633:12)
    at unpipe (/home/borisov/test/node-run-middleware/node_modules/unpipe/index.js:47:12)
    at send (/home/borisov/test/node-run-middleware/node_modules/finalhandler/index.js:275:3)
    at Immediate.<anonymous> (/home/borisov/test/node-run-middleware/node_modules/finalhandler/index.js:135:5)
    at Immediate.<anonymous> (/home/borisov/test/node-run-middleware/node_modules/express/lib/router/index.js:635:15)
    at runCallback (timers.js:674:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)

from node-run-middleware.

azaslavsky avatar azaslavsky commented on June 23, 2024

Anyone have any idea about what to do if this happens?

from node-run-middleware.

deejayres avatar deejayres commented on June 23, 2024

Just ran into this as well.

from node-run-middleware.

alflennik avatar alflennik commented on June 23, 2024

I'm getting this error from an entirely different setup that doesn't even include node-run-middleware. So maybe the problem is deeper - like Express itself.

from node-run-middleware.

therealpecus avatar therealpecus commented on June 23, 2024

this still happens if you have routes configured with sendFile:

app.get(CLIENT_ROUTES, function(req, res) {
  res.sendFile(join(DIST_FOLDER, 'browser', 'index.html'));
});

I tried every solution proposed above to no avail.

from node-run-middleware.

hotlib avatar hotlib commented on June 23, 2024

I solved it by passing original_req parameter:

app.runMiddleware('/another-route', {original_req: req}, function(err, data) {
  ...
});

this worked for me

from node-run-middleware.

danielponce263 avatar danielponce263 commented on June 23, 2024

Try to delete the response.json() of the api /sessions , it works for me.

from node-run-middleware.

Aminadav avatar Aminadav commented on June 23, 2024

If anyone wants to create a PR to fix it, I will merge it

from node-run-middleware.

dustinbolton avatar dustinbolton commented on June 23, 2024

I had this issue before I had a catchall route set up to 404. Basically when a url was accessed where no route matched then this happened. Adding a catchall after all other routes were registered (so it only runs if nothing else matched) fixed it in my case. app.all('*', ...

from node-run-middleware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.