Skip to content

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.

1 participant