@eeacms/volto-datahub 1.0.23 → 1.0.24

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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ ### [1.0.24](https://github.com/eea/volto-datahub/compare/1.0.23...1.0.24) - 13 June 2023
8
+
9
+ #### :hammer_and_wrench: Others
10
+
11
+ - Add redirect middleware [Tiberiu Ichim - [`7f739bd`](https://github.com/eea/volto-datahub/commit/7f739bd9aab070b4eb8dc196efb238985f930784)]
7
12
  ### [1.0.23](https://github.com/eea/volto-datahub/compare/1.0.22...1.0.23) - 12 June 2023
8
13
 
9
14
  #### :house: Internal changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-datahub",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "@eeacms/volto-datahub: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -77,13 +77,47 @@ function sitemap(req, res, next) {
77
77
  });
78
78
  }
79
79
 
80
+ function datasetRedirect(req, res, next) {
81
+ const prod_id = req.params['id'];
82
+
83
+ if (!prod_id) return next();
84
+
85
+ // example of id: DAT-238-en
86
+
87
+ const body = {
88
+ query: {
89
+ bool: {
90
+ must: [
91
+ {
92
+ match: {
93
+ prod_id,
94
+ },
95
+ },
96
+ ],
97
+ },
98
+ },
99
+ };
100
+
101
+ const urlES = getUrlES('datahub');
102
+
103
+ handleSearchRequest(body, { urlES }).then((result) => {
104
+ const total = result.hits.total.value;
105
+ if (!total) return next();
106
+
107
+ const hit = result.hits.hits[0];
108
+ const { _id } = hit;
109
+ res.redirect(301, `/en/datahub/datahubitem-view/${_id}`);
110
+ });
111
+ }
112
+
80
113
  export default function makeMiddlewares(config) {
81
114
  const middleware = express.Router();
82
115
  // middleware.use(express.json({ limit: config.settings.maxResponseSize }));
83
116
  middleware.use(express.urlencoded({ extended: true }));
84
117
 
85
118
  middleware.all('**/datahub/sitemap-data.xml', sitemap);
86
- middleware.id = 'datahub-sitemap';
119
+ middleware.all('**/datahub/dataset-redirect/:id', datasetRedirect);
120
+ middleware.id = 'datahub-middlewares';
87
121
 
88
122
  return middleware;
89
123
  }