ldn-inbox-server 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +55 -11
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -84,30 +84,51 @@ function doInboxGET(req,res) {
84
84
 
85
85
  function doInboxHEAD(req,res) {
86
86
  const pathItem = req.url.substring(INBOX_URL.length);
87
+ const id = pathItem.substring(1);
87
88
 
88
89
  logger.debug(`doInboxHEAD (for ${pathItem})`);
89
90
 
90
91
  if (pathItem === '/') {
91
- res.setHeader('Content-Type','application/ld+json');
92
+ const meta = getBody(`${id}.meta`);
93
+
94
+ if (meta) {
95
+ const metadata = JSON.parse(meta);
96
+ for (let property in metadata) {
97
+ res.setHeader(property,metadata[property]);
98
+ }
99
+ }
100
+ else {
101
+ res.setHeader('Content-Type','application/ld+json');
102
+ }
92
103
  res.writeHead(200);
93
104
  res.end();
94
105
  return;
95
106
  }
96
107
 
97
108
  if (pathItem.match(/^\/[A-Za-z0-9_-]+\.jsonld$/)) {
98
- const id = pathItem.substring(1);
99
109
  const result = getBody(id);
100
110
 
101
- if (result) {
102
- res.setHeader('Content-Type','application/ld+json');
103
- res.writeHead(200);
104
- res.end();
111
+ if (! result) {
112
+ res.writeHead(403);
113
+ res.end('Forbidden');
105
114
  return;
106
115
  }
116
+
117
+ const meta = getBody(`${id}.meta`);
118
+
119
+ if (meta) {
120
+ const metadata = JSON.parse(meta);
121
+ for (let property in metadata) {
122
+ res.setHeader(property,metadata[property]);
123
+ }
124
+ }
107
125
  else {
108
- res.writeHead(403);
109
- res.end('Forbidden');
126
+ res.setHeader('Content-Type','application/ld+json');
110
127
  }
128
+
129
+ res.writeHead(200);
130
+ res.end();
131
+ return;
111
132
  }
112
133
  else {
113
134
  res.writeHead(403);
@@ -127,17 +148,40 @@ function doInboxGET_Index(req,res) {
127
148
  "contains": notifications
128
149
  };
129
150
 
151
+ const meta = getBody(`.meta`);
152
+
153
+ if (meta) {
154
+ const metadata = JSON.parse(meta);
155
+ for (let property in metadata) {
156
+ res.setHeader(property,metadata[property]);
157
+ }
158
+ }
159
+ else {
160
+ res.setHeader('Content-Type','application/ld+json');
161
+ }
162
+
130
163
  res.writeHead(200);
131
164
  res.end(JSON.stringify(result,null,2));
132
165
  }
133
166
 
134
167
  function doInboxGET_Read(req,res) {
135
168
  const pathItem = req.url.substring(INBOX_URL.length);
136
-
137
- const result = getBody(pathItem.substring(1));
169
+ const id = pathItem.substring(1);
170
+ const result = getBody(id);
138
171
 
139
172
  if (result) {
140
- res.setHeader('Content-Type','application/ld+json');
173
+ const meta = getBody(`${id}.meta`);
174
+
175
+ if (meta) {
176
+ const metadata = JSON.parse(meta);
177
+ for (let property in metadata) {
178
+ res.setHeader(property,metadata[property]);
179
+ }
180
+ }
181
+ else {
182
+ res.setHeader('Content-Type','application/ld+json');
183
+ }
184
+
141
185
  res.writeHead(200);
142
186
  res.end(result);
143
187
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldn-inbox-server",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "A demonstration Event Notifications Inbox server",
5
5
  "main": "lib/index.js",
6
6
  "author": "Patrick Hochstenbach <Patrick.Hochstenbach@UGent.be>",