Skip to content

Commit 9d4c091

Browse files
committed
Support queryEntity on proxy endpoints
1 parent a6a0197 commit 9d4c091

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

context-provider/controllers/proxy/catfacts-api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function getAsNGSIv2(req, res) {
101101
//
102102
// The /ngsi-ld/v1/entities/:id endpoint responds with data in the NGSI-LD format
103103
//
104-
function getAsNgsiLD(req, res) {
104+
function getAsNgsiLD(req, res, asArray = false) {
105105
monitor('/ngsi-ld/v1/entities', 'Data requested from Cat Facts API', req.body);
106106
makeCatFactsRequest()
107107
.then((result) => {
@@ -120,7 +120,7 @@ function getAsNgsiLD(req, res) {
120120
} else {
121121
res.set('Content-Type', 'application/ld+json');
122122
}
123-
res.send(response);
123+
res.send(asArray ? [response] :response);
124124
})
125125
.catch((err) => {
126126
debug(err);

context-provider/controllers/proxy/openweathermap-api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function getAsNGSIv2(req, res) {
101101
//
102102
// The /ngsi-ld/v1/entities/:id endpoint responds with data in the NGSI-LD format
103103
//
104-
function getAsNgsiLD(req, res) {
104+
function getAsNgsiLD(req, res, asArray = false) {
105105
monitor('/ngsi-ld/v1/entities', 'Data requested from OpenWeatherMap API', req.body);
106106
makeWeatherRequest(req.params.queryString)
107107
.then((result) => {
@@ -121,7 +121,7 @@ function getAsNgsiLD(req, res) {
121121
} else {
122122
res.set('Content-Type', 'application/ld+json');
123123
}
124-
res.send(response);
124+
res.send(asArray ? [response] :response);
125125
})
126126
.catch((err) => {
127127
debug(err);

context-provider/controllers/proxy/random-api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function getAsNGSIv2(req, res) {
6161
//
6262
// The /ngsi-ld/v1/entities/:id endpoint responds with data in the NGSI-LD format
6363
//
64-
function getAsNgsiLD(req, res) {
64+
function getAsNgsiLD(req, res, asArray = false) {
6565
monitor('/ngsi-ld/v1/entities', 'Data requested from Random API', req.body);
6666
res.set('Content-Type', 'application/ld+json');
6767
const response = Formatter.formatAsLDResponse(req, null, (name, type) => {
@@ -73,7 +73,7 @@ function getAsNgsiLD(req, res) {
7373
} else {
7474
res.set('Content-Type', 'application/ld+json');
7575
}
76-
res.send(response);
76+
res.send(asArray ? [response] :response);
7777
}
7878

7979
//

context-provider/controllers/proxy/static-api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function getAsNGSIv2(req, res) {
7878
//
7979
// The /ngsi-ld/v1/entities/:id endpoint responds with data in the NGSI-LD format
8080
//
81-
function getAsNgsiLD(req, res) {
81+
function getAsNgsiLD(req, res, asArray = false) {
8282
const response = Formatter.formatAsLDResponse(req, null, (name, type) => {
8383
return staticValues[type.toLowerCase()];
8484
});
@@ -89,7 +89,7 @@ function getAsNgsiLD(req, res) {
8989
res.set('Content-Type', 'application/ld+json');
9090
}
9191

92-
res.send(response);
92+
res.send(asArray ? [response] :response);
9393
}
9494

9595
//

context-provider/controllers/proxy/twitter-api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function getAsNGSIv2(req, res) {
111111
//
112112
// The /ngsi-ld/v1/entities/:id endpoint responds with data in the NGSI-LD format
113113
//
114-
function getAsNgsiLD(req, res) {
114+
function getAsNgsiLD(req, res, asArray = false) {
115115
monitor('/ngsi-ld/v1/entities', 'Data requested from Twitter API', req.body);
116116

117117
makeTwitterRequest(
@@ -130,7 +130,7 @@ function getAsNgsiLD(req, res) {
130130
} else {
131131
res.set('Content-Type', 'application/ld+json');
132132
}
133-
res.send(response);
133+
res.send(asArray ? [response] :response);
134134
},
135135
(err) => {
136136
debug(err);

context-provider/routes/proxy-ld.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ function noOp(req, res) {
6969
res.send();
7070
}
7171

72+
73+
router.get('/catfacts/:type/:mapping/ngsi-ld/v1/entities', CatFactsNGSIProxy.getAsNgsiLD, true);
74+
router.get('/random/:type/:mapping/ngsi-ld/v1/entities', RandomNGSIProxy.getAsNgsiLD, true);
75+
router.get('/static/:type/:mapping/ngsi-ld/v1/entities', StaticNGSIProxy.getAsNgsiLD, true);
76+
router.get('/twitter/:type/:mapping/:queryString/ngsi-ld/v1/entities', TwitterNGSIProxy.getAsNgsiLD, true);
77+
router.get('/weather/:type/:mapping/:queryString/ngsi-ld/v1/entities', WeatherNGSIProxy.getAsNgsiLD, true);
78+
79+
80+
7281
router.get('/catfacts/:type/:mapping/ngsi-ld/v1/entities/:id', CatFactsNGSIProxy.getAsNgsiLD);
7382
router.get('/random/:type/:mapping/ngsi-ld/v1/entities/:id', RandomNGSIProxy.getAsNgsiLD);
7483
router.get('/static/:type/:mapping/ngsi-ld/v1/entities/:id', StaticNGSIProxy.getAsNgsiLD);

0 commit comments

Comments
 (0)