Skip to content
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

Allow plugins to register handler types #1521

Merged
merged 15 commits into from
Apr 5, 2014
Merged

Allow plugins to register handler types #1521

merged 15 commits into from
Apr 5, 2014

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Mar 25, 2014

Defines server.handler(name, method [, schema]) and plugin.handler(name, method [, schema])

Closes #1385

@@ -7,7 +7,6 @@ var Utils = require('./utils');
var Response = require('./response');
var Ext = require('./ext');
var File = require('./file');
var Directory = require('./directory');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave this here along with the server handler registration. Instead of the server constructor having the logic of adding the built-ins, create a function here and have the server call it. Keeps the inter dependencies cleaner.

@hueniverse
Copy link
Contributor

Please use the excellent work in #1511 for the missing documentation (the relevant parts, modified to this style).

@cjihrig
Copy link
Contributor Author

cjihrig commented Apr 1, 2014

@hueniverse updated

@hueniverse
Copy link
Contributor

I didn't mean to create a new file like methods.js which made sense because it had a lot of other logic. Just mean that the handlers definitions should be owned by the pack.

The docs still show passing the schema as a third argument to handler() which I don't want. I want the method itself to do this.

Also, cannot override the built-ins.

@cjihrig
Copy link
Contributor Author

cjihrig commented Apr 1, 2014

OK - will pull it back into pack.js.

Just so we're clear, this means that any new handlers will use Joi.any(), right?

The initial issue called for the ability to override the built-ins. Is it safe to assume that no handlers can be overridden once they are defined?

@hueniverse
Copy link
Contributor

Yes, no overrides. First win.

New handlers will need to verify the config using whatever they want, but the route handler config must still be an object with a single key that is Joi.object().

@cjihrig
Copy link
Contributor Author

cjihrig commented Apr 1, 2014

@hueniverse one more time

var server = Hapi.createServer('localhost', 8000);

// Defines new handler for routes on this server
server.handler('proxy', function (route, options) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad example since overriding existing is not allowed.

@@ -400,3 +397,15 @@ exports.invoke = function (request, event, callback) {
});
};


exports.registerDefaultHandlers = function (server) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shorter name. Like: register()

@cjihrig cjihrig closed this Apr 2, 2014
@hueniverse
Copy link
Contributor

Closed?

@cjihrig
Copy link
Contributor Author

cjihrig commented Apr 2, 2014

The way my code is currently set up, moving the schema validation into the handler generator is going to take some restructuring. If you look at my tests, I was expecting the user to pass in the handler generator. By making this change, non-builtins need to be wrapped at runtime. Also, by eliminating the third schema argument, the Pack.prototype._handler() function has to give the builtins special treatment. It's starting to seem a bit hacky.

@hueniverse
Copy link
Contributor

Ok. I'll give it a pass tonight so you can see what I mean.

@cjihrig cjihrig reopened this Apr 4, 2014
@cjihrig
Copy link
Contributor Author

cjihrig commented Apr 4, 2014

@hueniverse is this what you meant?

hueniverse pushed a commit that referenced this pull request Apr 5, 2014
Allow plugins to register handler types
@hueniverse hueniverse merged commit 458d17f into hapijs:master Apr 5, 2014
@hueniverse hueniverse added this to the 3.2.0 milestone Apr 5, 2014
@hueniverse hueniverse self-assigned this Apr 5, 2014
hueniverse pushed a commit that referenced this pull request Apr 6, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jan 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow plugins to register handler types
2 participants