Git Product home page Git Product logo

Comments (8)

mcavage avatar mcavage commented on May 1, 2024

Hi Andy,

A couple questions:

  1. What do you mean the request hangs? Is your authenticate method printing out "getAuthenticatedUser"? I.e., is your callback returning?
  2. Are you calling res.send() (or res.writeHead(), res.end() ), anywhere in your chain?
  3. What version of restify are you on?
  4. Can you paste in the route definition of a path where this is failing for you?

Lastly, somewhere in your main, try doing:

restify.log.level(restify.LogLevel.Trace);

which will cause restify to log all sorts of erroneous information :).

m

from node-restify.

andyb avatar andyb commented on May 1, 2024

Hey Mark

Thanks for the quick response :-)

  1. Literally the server just hangs until I kill node - the last trace message I see is
    2011-05-15 01:24:36Z TRACE: _parseRequest: params parsed as: {} and no the callback doesn't print, however if I move return next() out of the callback and into the root function then it does.
  2. In the main handler yes (see below) but it doesn't make it there if I have the async method in the pre handler as per my snippet above
  3. 0.3.1
  4. It's dead simple as I'm testing this out :-) (note pre is the array which contains authenticate function)

server.get('/users', pre, function(req, res,) {
res.send(200);
});

Let me know if you need more to go on. FYI the async call is a db lookup using mongoose.js if thats of any interest. Just to note if I don't make an async call and just return next() then it all works as expected.

thanks

Andy.

from node-restify.

mcavage avatar mcavage commented on May 1, 2024

Ok, so minor thing - since this is all prototype code, bump up to the latest restify (0.3.2-pre1). I doubt it will fix your problem, but anyway.

So, it sounds like the mongoose thing isn't actually returning if it works pulling next() out of the callback? Does that call work if you take restify out of the picture? i.e., just a:

models.User.findOne({email: "[email protected]"}, function(err, user){
    return console.log("Yay!");
});

Would that get printed? Sorry if that's a silly question and you've already tried that.

from node-restify.

andyb avatar andyb commented on May 1, 2024

Ok will bump v tomorrow but quick answer to your question yeah it works. It actually works fine in a main handler too.... it's only when it returns next() that for some reason it doesn't get called.

from node-restify.

mcavage avatar mcavage commented on May 1, 2024

Oh ok. Well, that's definitely strange then. So, you have then:

server.get('/users', [authenticate], function(req, res,) {
  res.send(200);
});

?

Looking at that closely it may be because currently the pre stuff only kicks in if you also have a post array. I will mess around with that today and see if I can recreate and fix.

from node-restify.

mcavage avatar mcavage commented on May 1, 2024

Hi Andy,

I tried to recreate this unsuccesfully - can you take a look at this code and see what's different structurally than what you're doing? (this works):

var restify = require('restify');

function before(req, res, next) {
  function anything() {
    return next();
  }
  return anything();
}

var server = restify.createServer();
server.get('/foo', [before], function(req, res, next) {
  res.send(200);
  return next();
});

server.listen(8080,  function() {
  console.log('GH-27 server up and running');
});


$ curl -is localhost:8080/foo
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Connection: close
Date: Wed, 15 Jun 2011 21:39:17 GMT
Server: node.js
x-request-id: ea93e841-9f35-4a90-bd93-0728509c8cac
x-response-time: 0
Content-Length: 0

from node-restify.

andyb avatar andyb commented on May 1, 2024

Hey Mark

Ok done some more digging around and I think its actually a problem with the async call not Restify as the above code works for me too - sorry for the distraction, appreciate the help.

Andy

from node-restify.

mcavage avatar mcavage commented on May 1, 2024

Ok no problem - let me know if you need any help!

from node-restify.

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.