halacious
halacious copied to clipboard
Links relative to the server root are also relative.
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"
}
}
}
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?