express-sweet-generator 1.0.10 → 1.0.11

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
@@ -1,6 +1,49 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.0.11] - 2023/7/12
5
+ ### Changed
6
+ - Moved the Ajax determination option (is_ajax) in the authentication configuration (config/authentication) to the basic configuration (config/config).
7
+
8
+ config/config.js:
9
+ ```js
10
+ /**
11
+ * How to determine if it is an ajax request.
12
+ * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
13
+ * For example, if there is no XMLHttpRequest in req(express.Request) and the Ajax endpoint starts with /api, a custom Ajax decision can be made like "return /^\/api\//.test(req.path)".
14
+ *
15
+ * @type {(req: express.Request) => boolean}
16
+ * @example
17
+ * is_ajax: req => {
18
+ * // If the request URL begins with /api, it is assumed to be Ajax.
19
+ * return /^\/api/.test(req.path);
20
+ * // return !!req.xhr;
21
+ * }
22
+ */
23
+ is_ajax: req => !!req.xhr,
24
+ ```
25
+ - The error handle option (error_handler) in the basic configuration (config/config.js) has been removed and an option to hook error handles (hook_handle_error) added instead.
26
+
27
+ config/config.js:
28
+ ```js
29
+ /**
30
+ * Hooks the default behavior on request errors.
31
+ * If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
32
+ *
33
+ * @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
34
+ * @example
35
+ * hook_handle_error: (err, req, res, next) => {
36
+ * if (err.status === 404)
37
+ * // If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
38
+ * res.render('error-404');
39
+ * else
40
+ * // For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
41
+ * res.render('error-unknown');
42
+ * },
43
+ */
44
+ hook_handle_error: undefined,
45
+ ```
46
+
4
47
  ## [1.0.10] - 2023/7/11
5
48
  ### Changed
6
49
  - The URL to redirect to when login fails (failure_redirect) option in the authentication configuration (config/authentication.js) can now be defined with a function.
@@ -197,4 +240,5 @@ All notable changes to this project will be documented in this file.
197
240
  [1.0.7]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.6...v1.0.7
198
241
  [1.0.8]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.7...v1.0.8
199
242
  [1.0.9]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.8...v1.0.9
200
- [1.0.10]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.9...v1.0.10
243
+ [1.0.10]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.9...v1.0.10
244
+ [1.0.11]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.10...v1.0.11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet-generator",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Express Sweet application generator.",
5
5
  "main": "bin/express-sweet-cli.js",
6
6
  "files": [
@@ -106,19 +106,4 @@ module.exports = {
106
106
  * @type {number}
107
107
  */
108
108
  expiration: 24 * 3600000,
109
-
110
- /**
111
- * How to determine if it is an ajax request.
112
- * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
113
- * For example, if there is no XMLHttpRequest in req(express.Request) and the Ajax endpoint starts with /api, a custom Ajax decision can be made like "return /^\/api\//.test(req.path)".
114
- *
115
- * @type {(req: express.Request) => boolean}
116
- * @example
117
- * is_ajax: req => {
118
- * // If the request URL begins with /api, it is assumed to be Ajax.
119
- * return /^\/api/.test(req.path);
120
- * // return !!req.xhr;
121
- * }
122
- */
123
- is_ajax: req => !!req.xhr
124
109
  }
@@ -51,28 +51,34 @@ module.exports = {
51
51
  },
52
52
 
53
53
  /**
54
- * This is a hook for error handling.
55
- * For example, you can use it when you want to send an external notification of the error received by this hook.
56
- *
54
+ * How to determine if it is an ajax request.
55
+ * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
56
+ * For example, if there is no XMLHttpRequest in req(express.Request) and the Ajax endpoint starts with /api, a custom Ajax decision can be made like "return /^\/api\//.test(req.path)".
57
+ *
58
+ * @type {(req: express.Request) => boolean}
59
+ * @example
60
+ * is_ajax: req => {
61
+ * // If the request URL begins with /api, it is assumed to be Ajax.
62
+ * return /^\/api/.test(req.path);
63
+ * // return !!req.xhr;
64
+ * }
65
+ */
66
+ is_ajax: req => !!req.xhr,
67
+
68
+ /**
69
+ * Hooks the default behavior on request errors.
70
+ * If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
71
+ *
72
+ * @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
57
73
  * @example
58
- * error_handler: async err => {
59
- * // Notify system administrator of error.
60
- * return new Promise((resolve, reject) => {
61
- * const sendmail = require('sendmail')();
62
- * sendmail({
63
- * from: 'no-reply@example.com',
64
- * to: 'administrator@example.com',
65
- * subject: 'Error occurred',
66
- * text: err.message
67
- * }, err => {
68
- * err ? reject(err) : resolve();
69
- * });
70
- * });
71
- * }
72
- *
73
- * @type {(err: any): void|Promise<void>}
74
+ * hook_handle_error: (err, req, res, next) => {
75
+ * if (err.status === 404)
76
+ * // If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
77
+ * res.render('error-404');
78
+ * else
79
+ * // For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
80
+ * res.render('error-unknown');
81
+ * },
74
82
  */
75
- error_handler: err => {
76
- console.error(`An error has occurred. Error message: ${err.message}`);
77
- }
83
+ hook_handle_error: undefined,
78
84
  }
@@ -15,7 +15,6 @@ export default class extends Modal {
15
15
  let user;
16
16
  if (this.#mode === 'update')
17
17
  user = (await this.#userApi.getUser(this.#userId)).data;
18
- console.log('user=', user);
19
18
  const node = this.render(user);
20
19
  const instance = new bootstrap.Modal(node);
21
20
  this.#ref = selectRef(node);
@@ -106,19 +106,4 @@ export default {
106
106
  * @type {number}
107
107
  */
108
108
  expiration: 24 * 3600000,
109
-
110
- /**
111
- * How to determine if it is an ajax request.
112
- * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
113
- * For example, if there is no XMLHttpRequest in req(express.Request) and the Ajax endpoint starts with /api, a custom Ajax decision can be made like "return /^\/api\//.test(req.path)".
114
- *
115
- * @type {(req: express.Request) => boolean}
116
- * @example
117
- * is_ajax: req => {
118
- * // If the request URL begins with /api, it is assumed to be Ajax.
119
- * return /^\/api/.test(req.path);
120
- * // return !!req.xhr;
121
- * }
122
- */
123
- is_ajax: req => !!req.xhr
124
109
  }
@@ -51,28 +51,34 @@ export default {
51
51
  },
52
52
 
53
53
  /**
54
- * This is a hook for error handling.
55
- * For example, you can use it when you want to send an external notification of the error received by this hook.
56
- *
54
+ * How to determine if it is an ajax request.
55
+ * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
56
+ * For example, if there is no XMLHttpRequest in req(express.Request) and the Ajax endpoint starts with /api, a custom Ajax decision can be made like "return /^\/api\//.test(req.path)".
57
+ *
58
+ * @type {(req: express.Request) => boolean}
59
+ * @example
60
+ * is_ajax: req => {
61
+ * // If the request URL begins with /api, it is assumed to be Ajax.
62
+ * return /^\/api/.test(req.path);
63
+ * // return !!req.xhr;
64
+ * }
65
+ */
66
+ is_ajax: req => !!req.xhr,
67
+
68
+ /**
69
+ * Hooks the default behavior on request errors.
70
+ * If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
71
+ *
72
+ * @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
57
73
  * @example
58
- * error_handler: async err => {
59
- * // Notify system administrator of error.
60
- * return new Promise((resolve, reject) => {
61
- * const sendmail = require('sendmail')();
62
- * sendmail({
63
- * from: 'no-reply@example.com',
64
- * to: 'administrator@example.com',
65
- * subject: 'Error occurred',
66
- * text: err.message
67
- * }, err => {
68
- * err ? reject(err) : resolve();
69
- * });
70
- * });
71
- * }
72
- *
73
- * @type {(err: any): void|Promise<void>}
74
+ * hook_handle_error: (err, req, res, next) => {
75
+ * if (err.status === 404)
76
+ * // If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
77
+ * res.render('error-404');
78
+ * else
79
+ * // For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
80
+ * res.render('error-unknown');
81
+ * },
74
82
  */
75
- error_handler: err => {
76
- console.error(`An error has occurred. Error message: ${err.message}`);
77
- }
83
+ hook_handle_error: undefined,
78
84
  }