-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle server methods without cache as special case #1922
Comments
@hueniverse It looks like this introduced another bug. The parameters being passed to the server method are not correct (see below) - looks like the args is getting reassigned to a function and then passed in as the argument to the serve method. |
@briandela What does your method function look like? |
Here is an example server method and code adding it: // Calculate the filename without an extension.
// For example '/usr/local/my.js' -> 'my'
function fileNameWithoutExt(filename) {
if(!filename) {
throw new Error('filename must be specfiied');
}
if(filename.indexOf('/', filename.length - '/'.length) !== -1
|| filename.indexOf('\\', filename.length - '\\'.length) !== -1){
throw new Error('filename ends with a slash and appears to be a directory');
}
var extension = path.extname(filename);
var withoutExt = path.basename(filename, extension);
return withoutExt;
}
server.method('fileNameWithoutExt', fileNameWithoutExt); Calling it later like this: // If the route has a prefix we use that, otherwise we take
// the filename without extension (e.g. about.js -> /about)
var prefix = routeDetails.prefix;
prefix = prefix || ('/' + server.methods.fileNameWithoutExt(filename) + '/'); In the above, It seems like function (err, result) {
methodNext(err, result, null, { msec: timer.elapsed(), error: err });
}; which appears to be from here https://github.com/hapijs/hapi/blob/master/lib/methods.js#L64 (with specific commit: Line 64 in f810016
|
Ok. Your method function is the problem. Yes - this used to work because of how the code was written but it was a coincidence. The function has to use the passed callback to return its value. You can't just pass it any function. This is clearly specified in the docs. |
Ah, I see it called out here: https://github.com/hapijs/hapi/blob/master/docs/Reference.md#servermethodmethod I had originally created them from the details at http://hapijs.com/tutorials/server-methods which shows the next but doesn't explicitly mention that the next callback is necessary. I'll create a PR to update those docs. Even though the previous behaviour was a coincidence/bug it may be worth putting a breakingchange label on 6.8.1 just to help if others run into this. |
For the record..
I can make a more prominent note earlier in the documentation though |
@nlf You're correct, I am wrong. Apologies for the confusion. |
No worries at all, and it can certainly be more clear. I'll add a note at the top where the function is actually defined as well. |
6.8.0 broke server methods that do not generate keyed values.
The text was updated successfully, but these errors were encountered: