Comments (8)
Hi Andy,
A couple questions:
- What do you mean the request hangs? Is your authenticate method printing out "getAuthenticatedUser"? I.e., is your callback returning?
- Are you calling res.send() (or res.writeHead(), res.end() ), anywhere in your chain?
- What version of restify are you on?
- 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.
Hey Mark
Thanks for the quick response :-)
- 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. - 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
- 0.3.1
- 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.
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.
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.
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.
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.
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.
Ok no problem - let me know if you need any help!
from node-restify.
Related Issues (20)
- New async/await handler support breaks `next(false)` functionality in current async handlers HOT 16
- ResourceNotFound with parameter length greater than 100 HOT 1
- Error when response already destroyed
- Using return in Async handlers logs entire response object to stdout HOT 4
- Allow overriding log in `plugins/audit`
- socket close on request done ?
- prePath middleware strips multiple slashes to an empty string
- An odd request can crash the process when `restify.pre.sanitizePath()` is used
- Does officially support Nodejs V18? HOT 1
- request/response serializers behave incorrectly for auditLogger plugin and Bunyan logger HOT 1
- handler error when running benchmark
- Is this repo actively maintained ?
- Restify support for nodejs v20 is merged but not released HOT 5
- Is restify.plugins.bodyParser's maxBodySize setting actually doing anything?
- v11.2.0 is not available at NPM HOT 7
- Migration from 8.5.1 to 10.0.0 causing issues
- bunyan is unmaintained, move to pino?
- Res.redirect won't work for async routes at all?
- Route handler still runs after returning response for earlier uncaught exception HOT 1
- Process crashes on invalid gzip body from client
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-restify.