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

Feature: server.decorate('request' ... ) #2481

Closed
danielb2 opened this issue Mar 25, 2015 · 15 comments
Closed

Feature: server.decorate('request' ... ) #2481

danielb2 opened this issue Mar 25, 2015 · 15 comments
Assignees
Labels
Milestone

Comments

@danielb2
Copy link
Contributor

@danielb2 danielb2 commented Mar 25, 2015

There's a lot of data on the request object. It would be useful to be able to decorate the request object with functions in addition to reply and server

@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented Mar 25, 2015

you can add anything to request.app on any server event like preHandler, would that solve your case or do you want to add a function to every request object?

@danielb2
Copy link
Contributor Author

@danielb2 danielb2 commented Mar 25, 2015

every request object

@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented Mar 25, 2015

you can do what I proposed but I'm also in favor of the decorate to work on request

@simon-p-r
Copy link

@simon-p-r simon-p-r commented Mar 27, 2015

👍 could server.decorate also decorate server.app?. Currently you are restricted to change value, for example if you want to pre-load the object before run-time this would be extremely useful. I looked at glue however you can only manipulate server.settings.app.

@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented Mar 27, 2015

Why decorate? You can just do server.app.yourNewFunction = function () {}

@simon-p-r
Copy link

@simon-p-r simon-p-r commented Mar 27, 2015

Thanks @AdriVanHoudt let me see if that will work! Just trying things out due to the experience gained from hueniversity

@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented Mar 27, 2015

👍

@hueniverse hueniverse added this to the 8.5.0 milestone May 21, 2015
@hueniverse hueniverse self-assigned this May 21, 2015
@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented May 21, 2015

I'll add updating the docs to reflect this to my to do list

On Thu, 21 May 2015 20:41 Eran Hammer notifications@github.com wrote:

Closed #2481 #2481 via 5f032a3
5f032a3
.


Reply to this email directly or view it on GitHub
#2481 (comment).

hueniverse added a commit that referenced this issue May 21, 2015
@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented May 21, 2015

@AdriVanHoudt missed that. Fixed.

@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented May 21, 2015

Thanks!

On Thu, 21 May 2015 21:22 Eran Hammer notifications@github.com wrote:

@AdriVanHoudt https://github.com/AdriVanHoudt missed that. Fixed.


Reply to this email directly or view it on GitHub
#2481 (comment).

@danielb2
Copy link
Contributor Author

@danielb2 danielb2 commented Jun 4, 2015

Thanks! Looks like it got used in https://github.com/hapijs/chairo/blob/master/lib/index.js#L25
already ;)

@ozum
Copy link

@ozum ozum commented Oct 15, 2015

How can I access request object from the function?

    server.decorate('request', 'setLocale', function(locale) {
        this.i18n.locale = locale;  // <-- this = undefined, I assumed this = request
    });

I assumed this is a reference to request object like decorate('reply', ...) example in API docs.

@kanongil
Copy link
Contributor

@kanongil kanongil commented Oct 15, 2015

@ozum It is bad form to revive old issues like this.

If you think you have found a bug, create a new issue. Otherwise I advice you to use the hapijs/discuss repo.

@ozum
Copy link

@ozum ozum commented Oct 15, 2015

@kanongil, oh, sorry, I thought this issue is a pinpoint to ask. I'm not sure it is a bug or by design. I will create a new issue.

@lock
Copy link

@lock lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants