@quintype/framework 7.28.4-image-below-fold.3 → 7.29.1

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
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [7.29.1](https://github.com/quintype/quintype-node-framework/compare/v7.29.0...v7.29.1) (2024-07-15)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **image-fold:** add bot request to store ([#432](https://github.com/quintype/quintype-node-framework/issues/432)) ([cd8b3f5](https://github.com/quintype/quintype-node-framework/commit/cd8b3f505eba5d50e57b146cb42484b8764646ad))
11
+
12
+ ## [7.29.0](https://github.com/quintype/quintype-node-framework/compare/v7.28.3...v7.29.0) (2024-07-15)
13
+
14
+
15
+ ### Features
16
+
17
+ * Add support for 410 Gone URL ([#431](https://github.com/quintype/quintype-node-framework/issues/431)) ([8820a42](https://github.com/quintype/quintype-node-framework/commit/8820a42a51f0a22f598d4562c0b2a154fce8931a))
18
+
5
19
  ### [7.28.3](https://github.com/quintype/quintype-node-framework/compare/v7.28.2...v7.28.3) (2024-06-13)
6
20
 
7
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.28.4-image-below-fold.3",
3
+ "version": "7.29.1",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -1,73 +1,77 @@
1
- const url = require("url");
2
- const logError = require("./logger").error;
3
- const { match, compile } = require("path-to-regexp");
1
+ const url = require('url')
2
+ const logError = require('./logger').error
3
+ const { match, compile } = require('path-to-regexp')
4
4
 
5
- function isUrl(url) {
5
+ function isUrl (url) {
6
6
  try {
7
- return new URL(url);
7
+ return new URL(url)
8
8
  } catch (err) {
9
- return false;
9
+ return false
10
10
  }
11
11
  }
12
12
 
13
- function processRedirects(req, res, next, sourceUrlArray, urls) {
14
- const query = url.parse(req.url, true) || {};
15
- const search = query.search || "";
13
+ function processRedirects (req, res, next, sourceUrlArray, urls) {
14
+ const query = url.parse(req.url, true) || {}
15
+ const search = query.search || ''
16
16
 
17
- sourceUrlArray.some((sourceUrl) => {
17
+ sourceUrlArray.some(sourceUrl => {
18
18
  try {
19
+ const statusCode = parseInt(urls[sourceUrl].statusCode, 10)
20
+ if (statusCode === 410) {
21
+ res.sendStatus(410)
22
+ return true
23
+ }
19
24
  if (urls[sourceUrl]) {
20
- const destinationPath = urls[sourceUrl].destinationUrl;
25
+ const destinationPath = urls[sourceUrl].destinationUrl
21
26
  const extractedSourceUrl = match(sourceUrl, {
22
- decode: decodeURIComponent,
23
- });
24
- const destinationUrl = isUrl(destinationPath);
27
+ decode: decodeURIComponent
28
+ })
29
+ const destinationUrl = isUrl(destinationPath)
25
30
  if (extractedSourceUrl) {
26
- let extractedDestinationUrl;
31
+ let extractedDestinationUrl
27
32
  if (destinationUrl) {
28
33
  extractedDestinationUrl = compile(destinationUrl.pathname, {
29
- encode: encodeURIComponent,
30
- });
34
+ encode: encodeURIComponent
35
+ })
31
36
  } else {
32
37
  extractedDestinationUrl = compile(destinationPath, {
33
- encode: encodeURIComponent,
34
- });
38
+ encode: encodeURIComponent
39
+ })
35
40
  }
36
- const dynamicKeys = extractedSourceUrl(req.path);
37
- const compiledPath = dynamicKeys && extractedDestinationUrl(dynamicKeys.params);
41
+ const dynamicKeys = extractedSourceUrl(req.path)
42
+ const compiledPath = dynamicKeys && extractedDestinationUrl(dynamicKeys.params)
38
43
  if (compiledPath) {
39
- const validStatusCodes = { 301: "max-age=604800", 302: "max-age=86400" };
40
- const statusCode = parseInt(urls[sourceUrl].statusCode, 10);
41
- const cacheValue = validStatusCodes[statusCode];
44
+ const validStatusCodes = { 301: 'max-age=604800', 302: 'max-age=86400' }
45
+ const cacheValue = validStatusCodes[statusCode]
42
46
  if (cacheValue) {
43
- res.set("cache-control", `public,${cacheValue}`);
47
+ res.set('cache-control', `public,${cacheValue}`)
44
48
  }
45
49
  res.redirect(
46
50
  statusCode,
47
51
  destinationUrl
48
52
  ? `${destinationUrl.protocol}//${destinationUrl.hostname}${compiledPath}${search}`
49
53
  : `${compiledPath}${search}`
50
- );
51
- return true;
54
+ )
55
+ return true
52
56
  }
53
57
  }
54
58
  }
55
59
  } catch (err) {
56
- console.log(`Redirection error on ${req.host}-----`, err);
60
+ console.log(`Redirection error on ${req.host}-----`, err)
57
61
  }
58
- });
62
+ })
59
63
  }
60
64
 
61
- exports.getRedirectUrl = async function getRedirectUrl(req, res, next, { redirectUrls, config }) {
62
- let sourceUrls;
63
- if (typeof redirectUrls === "function") {
64
- const redirectUrlsList = await redirectUrls(config);
65
- sourceUrls = Object.keys(redirectUrlsList);
65
+ exports.getRedirectUrl = async function getRedirectUrl (req, res, next, { redirectUrls, config }) {
66
+ let sourceUrls
67
+ if (typeof redirectUrls === 'function') {
68
+ const redirectUrlsList = await redirectUrls(config)
69
+ sourceUrls = Object.keys(redirectUrlsList)
66
70
  if (sourceUrls.length > 0) {
67
- processRedirects(req, res, next, sourceUrls, redirectUrlsList);
71
+ processRedirects(req, res, next, sourceUrls, redirectUrlsList)
68
72
  }
69
73
  } else if (redirectUrls) {
70
- sourceUrls = Object.keys(redirectUrls);
71
- sourceUrls.length > 0 && processRedirects(req, res, next, sourceUrls, redirectUrls);
74
+ sourceUrls = Object.keys(redirectUrls)
75
+ sourceUrls.length > 0 && processRedirects(req, res, next, sourceUrls, redirectUrls)
72
76
  }
73
- };
77
+ }