Skip to content

Commit

Permalink
change parent rel to up.
Browse files Browse the repository at this point in the history
  • Loading branch information
cainus committed Apr 10, 2014
1 parent 7974a32 commit 1e2ba04
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -29,7 +29,7 @@ app.use(hyperjsonConnect());
There is also an optional `options` parameter that lets you specify some
particular options:

* `defaultLinks` (boolean, defaults to true) : when true, 'parent' links
* `defaultLinks` (boolean, defaults to true) : when true, 'up' links
will automatically be added to every payload to point up one directory in your url.

* `protocol` (string or function, defaults to 'http') : All links will start with this
Expand Down Expand Up @@ -132,15 +132,15 @@ This can be called multiple times to add more links.
```javascript
res.object({thisis : "a test"})
.link("self", "http://localhost:8080/api/test")
.link("parent", "http://localhost:8080/api/")
.link("up", "http://localhost:8080/api/")
.link("kid", "http://localhost:8080/api/kid1")
.link("kid", "http://localhost:8080/api/kid2")
.send(); /* { thisis : "a test",
_links : {
self : {
href : "http://localhost:8080/api/test"
},
parent : {
up : {
href : "http://localhost:8080/api/"
},
kid : [{
Expand Down
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -18,13 +18,13 @@ var send = function(req, res, jsonObj, options) {
};

var addDefaultLinks = function(req, res, json, options) {
var current, parent;
var current, up;
if (json instanceof HyperJson) {
current = json.toObject();
} else {
current = json;
}
if (!current._links || !current._links.parent) {
if (!current._links || !current._links.up) {
try {
var host = 'localhost';
if (!!req.headers.host){
Expand All @@ -37,12 +37,12 @@ var addDefaultLinks = function(req, res, json, options) {
var base = protocol +
'://' +
(req.headers.host || 'localhost');
parent = urlgrey(base)
up = urlgrey(base)
.hostname(req.headers.host || 'localhost')
.path(req.url)
.parent()
.toString();
json.link("parent", parent);
json.link("up", up);
} catch (ex) {
if (ex.message !== "The current path has no parent path") {
throw ex;
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "hyperjson-connect",
"version": "0.10.0",
"version": "0.11.0",
"description": "connect middleware for hyperjson support",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions test/index.js
Expand Up @@ -116,7 +116,7 @@ describe("the middleware", function(){
done();
});
});
it("doesn;t add a parent link to sub resources", function(done){
it("doesn't add a `up` link to sub resources", function(done){
app.get("/api/resource", function(req, res){
res.object({"test" : true}).send();
});
Expand Down Expand Up @@ -163,7 +163,7 @@ describe("the middleware", function(){
var expected = {
"test": true,
"_links": {
"parent": {
"up": {
"href": "https://localhost:1337/api"
}
}
Expand Down Expand Up @@ -193,7 +193,7 @@ describe("the middleware", function(){
it("can output collections", function(done){
testRoot(done);
});
it("adds a parent link to sub resources", function(done){
it("adds an up link to sub resources", function(done){
app.get("/api/resource", function(req, res){
res.object({"test" : true}).send();
});
Expand All @@ -203,7 +203,7 @@ describe("the middleware", function(){
var expected = {
test: true,
_links: {
parent: {
up : {
href: 'http://localhost:1337/api' } } };
JSON.parse(body).should.eql(expected);
done();
Expand All @@ -223,7 +223,7 @@ describe("the middleware", function(){
var expected = {
test: true,
_links: {
parent: {
up : {
href: 'http://zombo.com:1337/api' } } };
JSON.parse(body).should.eql(expected);
done();
Expand All @@ -241,7 +241,7 @@ describe("the middleware", function(){
var expected = {
test: true,
_links: {
parent: {
up : {
href: 'http://localhost:1337/api' } } };
JSON.parse(body).should.eql(expected);
done();
Expand Down

0 comments on commit 1e2ba04

Please sign in to comment.