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

Links relative to the server root are also relative. #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JorgenEvens
Copy link

When configuring links that are relative to the root of the webserver in combination with the absolute=true plugin option causes non-absolute links to be generated.

I think the problem lies in the isRelativePath check, which should also consider paths relative to the server root as relative.

Example:

server.register({
    register: require('halacious'),
    options: { absolute: true }
})
.then(() => {
    server.route({
        method: 'GET',
        path: '/items',
        handler: function(req, reply) { reply({}); },
        config: {
            plugins: {
                hal: {
                    links: {
                        keys: '/keys',
                        values: '/values'
                    }
                }
            }
        }
    });
})
.then(() => {
    server.start();
})

Will currently return the following, note that the href for keys and values are not absolute.

{
  "_links": {
    "self": {
      "href": "http://localhost:5000/items"
    },
    "keys": {
      "href": "/keys"
    },
    "values": {
      "href": "/values"
    }
  }
}

@JorgenEvens
Copy link
Author

JorgenEvens commented Sep 30, 2016

Maybe this needs a different fix, as I just discovered that links which do not have a leading / also suffer from this problem.

hal: {
    links: {
        keys: 'keys',
        values: 'values'
    }
}

Results in

{
  "_links": {
    "self": {
      "href": "http://localhost:5000/items"
    },
    "keys": {
      "href": "keys"
    },
    "values": {
      "href": "values"
    }
  }
}

Would the inverse of https://github.com/bleupen/halacious/blob/master/lib/plugin.js#L632 do the job?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant