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

JS: Improved Hapi support #11146

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

JS: Improved Hapi support #11146

wants to merge 4 commits into from

Conversation

mbaluda
Copy link

@mbaluda mbaluda commented Nov 7, 2022

  • server defined by hapi/Glue
  • server from plugin parameter
  • handlers defined as Array
  • add req.url.origin to RequestInputAccess

- server defined by Glue
@github-actions github-actions bot added the JS label Nov 7, 2022
// server inside a plugin
// TODO match `function (server, options)`
exists(Function f |
this.(DataFlow::ParameterNode).getParameter() = f.getParameter(0) and
f.getParameter(0).getName() = "server" and
f.getParameter(1).getName() = "options"
)
Copy link
Contributor

@erik-krogh erik-krogh Nov 8, 2022

Choose a reason for hiding this comment

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

How is this function (server, options) used?
I suppose there is some call to Hapi that registers the plugin?
I think that registration call should be the ServerDefinition.

Copy link
Author

@mbaluda mbaluda Nov 8, 2022

Choose a reason for hiding this comment

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

I agree it can be made more precise by using the registration as definition...

The docs say:

At their core plugins are an object with a register property, that is a function with the signature async function (server, options). Additionally the plugin object has a required name property and several optional properties including version.

For example:

function after(server, options) {
  server. Route([
    {
      "method": "GET",
      "path": "/authenticate/{id}",
      handler(request) {
        ...
      }
}

function register(server, options) {
  server.dependency(options.dependencies || [], server_ => after(server_, options));
}

exports.plugin = { register, pkg };

and

const myPlugin = {
    name: 'myPlugin',
    version: '1.0.0',
    register: async function (server, options) {
        ...
    }
};

@owen-mc owen-mc changed the title Improved Hapi support JS: Improved Hapi support Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants