express-sweet 2.0.9 → 3.0.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +69 -1
  2. package/README.md +1039 -2137
  3. package/configuration_sample/cjs/authentication.js +50 -15
  4. package/configuration_sample/cjs/config.js +38 -21
  5. package/configuration_sample/cjs/database.js +90 -4
  6. package/configuration_sample/cjs/logging.js +41 -0
  7. package/configuration_sample/cjs/view.js +19 -1
  8. package/configuration_sample/esm/authentication.js +48 -15
  9. package/configuration_sample/esm/config.js +39 -22
  10. package/configuration_sample/esm/database.js +90 -4
  11. package/configuration_sample/esm/logging.js +41 -0
  12. package/configuration_sample/esm/view.js +20 -2
  13. package/dist/build.cjs +8 -8
  14. package/dist/build.mjs +4 -4
  15. package/package.json +9 -4
  16. package/types/database/DatabaseManager.d.ts +95 -0
  17. package/types/database/Model.d.ts +183 -20
  18. package/types/database/index.d.ts +47 -3
  19. package/types/database/loadModels.d.ts +19 -4
  20. package/types/handlebars_helpers/array.d.ts +3 -1
  21. package/types/handlebars_helpers/comparison.d.ts +55 -19
  22. package/types/handlebars_helpers/date.d.ts +3 -1
  23. package/types/handlebars_helpers/html.d.ts +6 -2
  24. package/types/handlebars_helpers/index.d.ts +73 -9
  25. package/types/handlebars_helpers/layouts.d.ts +5 -1
  26. package/types/handlebars_helpers/math.d.ts +21 -7
  27. package/types/handlebars_helpers/number.d.ts +3 -1
  28. package/types/handlebars_helpers/object.d.ts +6 -2
  29. package/types/handlebars_helpers/string.d.ts +9 -3
  30. package/types/index.d.ts +92 -5
  31. package/types/interfaces/AuthenticationConfig.d.ts +38 -1
  32. package/types/interfaces/BasicConfig.d.ts +26 -1
  33. package/types/interfaces/DatabaseConfig.d.ts +45 -1
  34. package/types/interfaces/LoggingConfig.d.ts +49 -0
  35. package/types/interfaces/ViewConfig.d.ts +21 -2
  36. package/types/interfaces/index.d.ts +25 -11
  37. package/types/middlewares/Authentication.d.ts +43 -6
  38. package/types/middlewares/CORS.d.ts +23 -5
  39. package/types/middlewares/Environment.d.ts +30 -4
  40. package/types/middlewares/ErrorHandler.d.ts +27 -5
  41. package/types/middlewares/Global.d.ts +20 -6
  42. package/types/middlewares/Http.d.ts +22 -5
  43. package/types/middlewares/Local.d.ts +35 -8
  44. package/types/middlewares/View.d.ts +39 -8
  45. package/types/middlewares/index.d.ts +47 -7
  46. package/types/mount.d.ts +16 -3
  47. package/types/routing/Router.d.ts +49 -7
  48. package/types/routing/index.d.ts +37 -1
  49. package/types/services/Authentication.d.ts +79 -16
  50. package/types/services/index.d.ts +33 -1
  51. package/types/types/global.d.ts +29 -8
  52. package/types/utils/Types.d.ts +5 -3
  53. package/types/utils/index.d.ts +71 -9
  54. package/types/utils/isArray.d.ts +12 -3
  55. package/types/utils/isAsyncFunction.d.ts +12 -5
  56. package/types/utils/isFunction.d.ts +13 -6
  57. package/types/utils/isObject.d.ts +14 -3
  58. package/types/utils/isString.d.ts +15 -4
  59. package/types/utils/loadAuthenticationConfig.d.ts +13 -3
  60. package/types/utils/loadBasicConfig.d.ts +13 -3
  61. package/types/utils/loadDatabaseConfig.d.ts +34 -3
  62. package/types/utils/loadLoggingConfig.d.ts +16 -0
  63. package/types/utils/loadViewConfig.d.ts +28 -3
  64. package/types/database/Database.d.ts +0 -18
  65. package/types/interfaces/BoundingBox.d.ts +0 -25
  66. package/types/interfaces/FaceDetails.d.ts +0 -30
  67. package/types/interfaces/FaceDetailsEmotions.d.ts +0 -40
  68. package/types/interfaces/FaceMatch.d.ts +0 -31
  69. package/types/interfaces/IndexFaceDetails.d.ts +0 -29
  70. package/types/interfaces/RekognitionOptions.d.ts +0 -26
  71. package/types/interfaces/SesOptions.d.ts +0 -27
@@ -1,4 +1,4 @@
1
- const UserModel = require('../models/UserModel');
1
+ // const UserModel = require('../models/UserModel');
2
2
 
3
3
  /**
4
4
  * User authentication configuration interface.
@@ -23,6 +23,20 @@ module.exports = {
23
23
  */
24
24
  cookie_name: 'connect.sid',
25
25
 
26
+ /**
27
+ * Specifies the boolean value for the Secure Set-Cookie attribute.
28
+ * The default is true, which sets the Secure attribute on the cookie.
29
+ * @type {boolean|undefined}
30
+ */
31
+ cookie_secure: false,
32
+
33
+ /**
34
+ * Specifies the boolean value for the HttpOnly Set-Cookie attribute.
35
+ * Defaults to true, which sets the HttpOnly attribute on the cookie.
36
+ * @type {boolean|undefined}
37
+ */
38
+ cookie_httpOnly: true,
39
+
26
40
  /**
27
41
  * If the session is stored in "redis", this field is required and should be set to the hostname of the Redis server.
28
42
  * For example, to connect to redis on localhost on port 6379, set "redis://localhost:6379".
@@ -52,7 +66,18 @@ module.exports = {
52
66
 
53
67
  /**
54
68
  * URL to redirect after log off, defaults to `/login`.
55
- * @type {string}
69
+ * @type {string|((req: express.Request, res: express.Response) => string)}
70
+ * @example
71
+ * ```js
72
+ * // Set the URL to redirect to in case of login failure as a string.
73
+ * failure_redirect: '/login',
74
+ *
75
+ * // Dynamically set the url to redirect to on login failure.
76
+ * failure_redirect: (req, res) => {
77
+ * // If the role stored in the cookie is admin, redirect to the admin login screen.
78
+ * return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
79
+ * },
80
+ * ```
56
81
  */
57
82
  failure_redirect: '/login',
58
83
 
@@ -66,13 +91,14 @@ module.exports = {
66
91
  * @type {(username: string, password: string, req: express.Request) => Promise<{[key: string]: any}|null>}
67
92
  */
68
93
  authenticate_user: async (username, password, req) => {
69
- return UserModel.findOne({
70
- where: {
71
- email: username,
72
- password
73
- },
74
- raw: true
75
- });
94
+ // Sample hardcoded return for demonstration purposes.
95
+ // In actual implementation, retrieve user information from database.
96
+ // For example, using UserModel: UserModel.findOne({ where: { email: username, password }, raw: true });
97
+ return {
98
+ id: 1,
99
+ email: 'user@example.com',
100
+ name: 'Sample User'
101
+ };
76
102
  },
77
103
 
78
104
  /**
@@ -83,21 +109,30 @@ module.exports = {
83
109
  * @type {(id: number|string) => Promise<{[key: string]: any}>}
84
110
  */
85
111
  subscribe_user: async (id) => {
86
- return UserModel.findOne({
87
- where: {id},
88
- raw: true
89
- });
112
+ // Sample hardcoded return for demonstration purposes.
113
+ // In actual implementation, retrieve user information from database.
114
+ // For example, using UserModel: UserModel.findOne({ where: { id }, raw: true });
115
+ return {
116
+ id: 1,
117
+ email: 'user@example.com',
118
+ name: 'Sample User',
119
+ role: 'user'
120
+ };
90
121
  },
91
122
 
92
123
  /**
93
124
  * URL without authentication. If the URL described in the access URL partially matches, authentication will not be performed, defaults to none.
94
125
  * @type {(string|RegExp)[]}
95
126
  */
96
- allow_unauthenticated: ['/api'],
127
+ allow_unauthenticated: [
128
+ // Example: Allow login endpoint to bypass authentication
129
+ // In actual implementation, specify the endpoints you want to exclude from authentication
130
+ '/api/login'
131
+ ],
97
132
 
98
133
  /**
99
134
  * Authenticated user session expiration, defaults to 24 hours (24 * 3600000).
100
135
  * @type {number}
101
136
  */
102
- expiration: 24 * 3600000
137
+ expiration: 24 * 3600000,
103
138
  }
@@ -20,7 +20,7 @@ module.exports = {
20
20
  * Maximum body size you can request, defaults to `100kb`.
21
21
  * @type {string|number}
22
22
  */
23
- max_body_size: '100kb',
23
+ max_body_size: '100mb',
24
24
 
25
25
  /**
26
26
  * Absolute path to the router directory, defaults to `<application root directory>/routes`.
@@ -40,35 +40,52 @@ module.exports = {
40
40
  * The default value is the referrer's origin (eg https://example.com).
41
41
  * @type {(baseUrl: string): string}
42
42
  * @example
43
+ * ```js
43
44
  * rewrite_base_url: baseUrl => {
44
45
  * return `${baseUrl}/admin`;
45
46
  * }
47
+ * ```
46
48
  */
47
49
  rewrite_base_url: baseUrl => {
48
50
  return baseUrl;
49
51
  },
50
52
 
51
53
  /**
52
- * This is a hook for error handling.
53
- * For example, you can use it when you want to send an external notification of the error received by this hook.
54
- * @type {(error: any): void|Promise<void>}
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
+ * @type {(req: express.Request) => boolean}
58
+ * @example
59
+ * ```js
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
+ */
67
+ is_ajax: req => !!req.xhr,
68
+
69
+ /**
70
+ * Hooks the default behavior on request errors.
71
+ * If unset, simply returns an error HTTP status. (<code>res.status(error.status||500).end();</code>)
72
+ * @type {(error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
55
73
  * @example
56
- * error_handler: async error => {
57
- * // Notify system administrator of error.
58
- * return new Promise((resolve, reject) => {
59
- * const sendmail = require('sendmail')();
60
- * sendmail({
61
- * from: 'no-reply@example.com',
62
- * to: 'administrator@example.com',
63
- * subject: 'Error occurred',
64
- * text: error.message
65
- * }, error => {
66
- * error ? reject(error) : resolve();
67
- * });
68
- * });
69
- * }
74
+ * ```js
75
+ * hook_handle_error: (error, req, res, next) => {
76
+ * if (error.status === 404)
77
+ * // If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
78
+ * res.render('errors/404');
79
+ * else
80
+ * // For other errors, unknown error screen (views/error/500.hbs) is displayed.
81
+ * res.render('error/500');
82
+ * },
83
+ * ```
70
84
  */
71
- error_handler: error => {
72
- console.error(`An error has occurred. Error message: ${error.message}`);
73
- }
85
+ hook_handle_error: (error, req, res, next) => {
86
+ if (error.status === 404)
87
+ res.status(404).render('errors/404', {isErrorPage: true});
88
+ else
89
+ res.status(500).render('errors/500', {isErrorPage: true});
90
+ },
74
91
  }
@@ -1,7 +1,53 @@
1
1
  /**
2
- * Database configuration.
2
+ * Sequelize Database Configuration
3
+ *
4
+ * @description Database connection settings for different environments
5
+ * Includes connection pool configuration for each environment
6
+ *
7
+ * @example
8
+ * // Connection pool configuration examples
9
+ * // The max value must be set appropriately according to the DB's max_connections
10
+ *
11
+ * // How to check max_connections in MariaDB:
12
+ * // SHOW VARIABLES LIKE 'max_connections';
13
+ * // +-----------------+-------+
14
+ * // | Variable_name | Value |
15
+ * // +-----------------+-------+
16
+ * // | max_connections | 151 |
17
+ * // +-----------------+-------+
18
+ *
19
+ * // Configuration example when max_connections=151:
20
+ * pool: {
21
+ * // Maximum 100 connections (66.2% usage of max_connections=151)
22
+ * // Keep total connections from all instances within 70-80% of max_connections
23
+ * max: 100,
24
+ * // Maintain 10 connections constantly (ensures stability during load increases)
25
+ * min: 10,
26
+ * // 10 second timeout for connection acquisition
27
+ * acquire: 10000,
28
+ * // Mark for deletion after 3 seconds of inactivity
29
+ * idle: 3000,
30
+ * // Check for idle connections every 10 seconds
31
+ * evict: 10000
32
+ * }
33
+ *
34
+ * // Configuration example when max_connections=5297:
35
+ * pool: {
36
+ * // Maximum 300 connections per instance (6 instances peak = 1800 connections = 34.0% usage)
37
+ * // Distribute connections across multiple instances while staying within safe limits
38
+ * max: 300,
39
+ * // Maintain 30 connections constantly (ensures stability during high load)
40
+ * min: 30,
41
+ * // 30 second timeout for connection acquisition
42
+ * acquire: 30000,
43
+ * // Mark for deletion after 10 seconds of inactivity
44
+ * idle: 10000,
45
+ * // Check for idle connections every 30 seconds
46
+ * evict: 30000
47
+ * }
3
48
  */
4
49
  module.exports = {
50
+ // Development environment configuration
5
51
  development: {
6
52
  username: 'root',
7
53
  password: 'password',
@@ -10,8 +56,22 @@ module.exports = {
10
56
  port: undefined,
11
57
  dialect: 'mariadb',
12
58
  timezone: '+09:00',
13
- logging: false
59
+ logging: false,
60
+ // pool: {
61
+ // // Maximum connections (adjust based on your DB's max_connections)
62
+ // max: 100,
63
+ // // Maintain minimum connections constantly
64
+ // min: 10,
65
+ // // Connection acquisition timeout
66
+ // acquire: 10000,
67
+ // // Mark for deletion after inactivity
68
+ // idle: 2000,
69
+ // // Check for idle connections interval
70
+ // evict: 10000
71
+ // }
14
72
  },
73
+
74
+ // Test environment configuration
15
75
  test: {
16
76
  username: 'root',
17
77
  password: 'password',
@@ -20,8 +80,22 @@ module.exports = {
20
80
  port: undefined,
21
81
  dialect: 'mariadb',
22
82
  timezone: '+09:00',
23
- logging: false
83
+ logging: false,
84
+ // pool: {
85
+ // // Maximum connections (adjust based on your DB's max_connections)
86
+ // max: 100,
87
+ // // Maintain minimum connections constantly
88
+ // min: 10,
89
+ // // Connection acquisition timeout
90
+ // acquire: 10000,
91
+ // // Mark for deletion after inactivity
92
+ // idle: 3000,
93
+ // // Check for idle connections interval
94
+ // evict: 10000
95
+ // }
24
96
  },
97
+
98
+ // Production environment configuration
25
99
  production: {
26
100
  username: 'root',
27
101
  password: 'password',
@@ -30,6 +104,18 @@ module.exports = {
30
104
  port: undefined,
31
105
  dialect: 'mariadb',
32
106
  timezone: '+09:00',
33
- logging: false
107
+ logging: false,
108
+ // pool: {
109
+ // // Maximum connections (adjust based on your DB's max_connections and instance count)
110
+ // max: 300,
111
+ // // Maintain minimum connections constantly
112
+ // min: 30,
113
+ // // Connection acquisition timeout
114
+ // acquire: 30000,
115
+ // // Mark for deletion after inactivity
116
+ // idle: 10000,
117
+ // // Check for idle connections interval
118
+ // evict: 30000
119
+ // }
34
120
  }
35
121
  }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Logging configuration interface.
3
+ */
4
+ module.exports = {
5
+ /**
6
+ * Morgan logging format. Common formats: 'combined', 'common', 'dev', 'short', 'tiny'
7
+ * You can also define custom format string, defaults to 'combined'.
8
+ * @type {string}
9
+ * @example
10
+ * ```js
11
+ * // Use predefined format
12
+ * format: 'combined',
13
+ *
14
+ * // Use custom format
15
+ * format: ':method :url :status :res[content-length] - :response-time ms',
16
+ * ```
17
+ */
18
+ format: 'combined',
19
+
20
+ /**
21
+ * Function to determine if logging should be skipped for a request.
22
+ * Return true to skip logging, false to log the request, defaults to none (undefined).
23
+ * @type {(req: express.Request, res: express.Response) => boolean}
24
+ * @example
25
+ * ```js
26
+ * // Skip logging for successful requests
27
+ * skip: (req, res) => res.statusCode < 400,
28
+ *
29
+ * // Skip logging for specific routes
30
+ * skip: (req, res) => req.path === '/health',
31
+ *
32
+ * // Skip logging in test environment
33
+ * skip: (req, res) => process.env.NODE_ENV === 'test',
34
+ * ```
35
+ */
36
+ skip: (req, res) => {
37
+ // Example: Skip logging for health check endpoints
38
+ // In actual implementation, customize based on your requirements
39
+ return req.path === '/health';
40
+ }
41
+ }
@@ -32,5 +32,23 @@ module.exports = {
32
32
  * Extension for templates & partials, defaults to `.hbs`,
33
33
  * @type {string}
34
34
  */
35
- extension: '.hbs'
35
+ extension: '.hbs',
36
+
37
+ /**
38
+ * Hook function just before the view is rendered.
39
+ * For example, you can set your own local variables that can be used within the view.
40
+ * @type {(res: express.Response) => Promise<void>|void}
41
+ * @example
42
+ * ```js
43
+ * // The message set here can be referenced in the view as {{message}}.
44
+ * beforeRender: (req, res) => {
45
+ * res.locals.extra = 'Extra';
46
+ * }
47
+ * ```
48
+ */
49
+ beforeRender: (req, res) => {
50
+ // Example: Set local variables that can be used in templates
51
+ // In actual implementation, set the variables you need in your views
52
+ res.locals.message = 'Hello World';
53
+ }
36
54
  }
@@ -1,4 +1,4 @@
1
- import UserModel from '../models/UserModel';
1
+ // import UserModel from '../models/UserModel.js';
2
2
 
3
3
  /**
4
4
  * User authentication configuration interface.
@@ -23,6 +23,20 @@ export default {
23
23
  */
24
24
  cookie_name: 'connect.sid',
25
25
 
26
+ /**
27
+ * Specifies the boolean value for the Secure Set-Cookie attribute.
28
+ * The default is true, which sets the Secure attribute on the cookie.
29
+ * @type {boolean|undefined}
30
+ */
31
+ cookie_secure: false,
32
+
33
+ /**
34
+ * Specifies the boolean value for the HttpOnly Set-Cookie attribute.
35
+ * Defaults to true, which sets the HttpOnly attribute on the cookie.
36
+ * @type {boolean|undefined}
37
+ */
38
+ cookie_httpOnly: true,
39
+
26
40
  /**
27
41
  * If the session is stored in "redis", this field is required and should be set to the hostname of the Redis server.
28
42
  * For example, to connect to redis on localhost on port 6379, set "redis://localhost:6379".
@@ -52,7 +66,16 @@ export default {
52
66
 
53
67
  /**
54
68
  * URL to redirect after log off, defaults to `/login`.
55
- * @type {string}
69
+ * @type {string|((req: express.Request, res: express.Response) => string)}
70
+ * @example
71
+ * // Set the URL to redirect to in case of login failure as a string.
72
+ * failure_redirect: '/login',
73
+ *
74
+ * // Dynamically set the url to redirect to on login failure.
75
+ * failure_redirect: (req, res) => {
76
+ * // If the role stored in the cookie is admin, redirect to the admin login screen.
77
+ * return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
78
+ * },
56
79
  */
57
80
  failure_redirect: '/login',
58
81
 
@@ -66,13 +89,14 @@ export default {
66
89
  * @type {(username: string, password: string, req: express.Request) => Promise<{[key: string]: any}|null>}
67
90
  */
68
91
  authenticate_user: async (username, password, req) => {
69
- return UserModel.findOne({
70
- where: {
71
- email: username,
72
- password
73
- },
74
- raw: true
75
- });
92
+ // Sample hardcoded return for demonstration purposes.
93
+ // In actual implementation, retrieve user information from database.
94
+ // For example, using UserModel: UserModel.findOne({ where: { email: username, password }, raw: true });
95
+ return {
96
+ id: 1,
97
+ email: 'user@example.com',
98
+ name: 'Sample User'
99
+ };
76
100
  },
77
101
 
78
102
  /**
@@ -83,21 +107,30 @@ export default {
83
107
  * @type {(id: number|string) => Promise<{[key: string]: any}>}
84
108
  */
85
109
  subscribe_user: async (id) => {
86
- return UserModel.findOne({
87
- where: {id},
88
- raw: true
89
- });
110
+ // Sample hardcoded return for demonstration purposes.
111
+ // In actual implementation, retrieve user information from database.
112
+ // For example, using UserModel: UserModel.findOne({ where: { id }, raw: true });
113
+ return {
114
+ id: 1,
115
+ email: 'user@example.com',
116
+ name: 'Sample User',
117
+ role: 'user'
118
+ };
90
119
  },
91
120
 
92
121
  /**
93
122
  * URL without authentication. If the URL described in the access URL partially matches, authentication will not be performed, defaults to none.
94
123
  * @type {(string|RegExp)[]}
95
124
  */
96
- allow_unauthenticated: ['/api'],
125
+ allow_unauthenticated: [
126
+ // Example: Allow login endpoint to bypass authentication
127
+ // In actual implementation, specify the endpoints you want to exclude from authentication
128
+ '/api/login'
129
+ ],
97
130
 
98
131
  /**
99
132
  * Authenticated user session expiration, defaults to 24 hours (24 * 3600000).
100
133
  * @type {number}
101
134
  */
102
- expiration: 24 * 3600000
135
+ expiration: 24 * 3600000,
103
136
  }
@@ -1,4 +1,4 @@
1
- import path from 'path';
1
+ import path from 'node:path';
2
2
 
3
3
  /**
4
4
  * EXPRESS SWEET basic configuration interface.
@@ -20,7 +20,7 @@ export default {
20
20
  * Maximum body size you can request, defaults to `100kb`.
21
21
  * @type {string|number}
22
22
  */
23
- max_body_size: '100kb',
23
+ max_body_size: '100mb',
24
24
 
25
25
  /**
26
26
  * Absolute path to the router directory, defaults to `<application root directory>/routes`.
@@ -40,35 +40,52 @@ export default {
40
40
  * The default value is the referrer's origin (eg https://example.com).
41
41
  * @type {(baseUrl: string): string}
42
42
  * @example
43
+ * ```js
43
44
  * rewrite_base_url: baseUrl => {
44
45
  * return `${baseUrl}/admin`;
45
46
  * }
47
+ * ```
46
48
  */
47
49
  rewrite_base_url: baseUrl => {
48
50
  return baseUrl;
49
51
  },
50
52
 
51
53
  /**
52
- * This is a hook for error handling.
53
- * For example, you can use it when you want to send an external notification of the error received by this hook.
54
- * @type {(error: any): void|Promise<void>}
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
+ * @type {(req: express.Request) => boolean}
58
+ * @example
59
+ * ```js
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
+ */
67
+ is_ajax: req => !!req.xhr,
68
+
69
+ /**
70
+ * Hooks the default behavior on request errors.
71
+ * If unset, simply returns an error HTTP status. (<code>res.status(error.status||500).end();</code>)
72
+ * @type {(error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
55
73
  * @example
56
- * error_handler: async error => {
57
- * // Notify system administrator of error.
58
- * return new Promise((resolve, reject) => {
59
- * const sendmail = require('sendmail')();
60
- * sendmail({
61
- * from: 'no-reply@example.com',
62
- * to: 'administrator@example.com',
63
- * subject: 'Error occurred',
64
- * text: error.message
65
- * }, error => {
66
- * error ? reject(error) : resolve();
67
- * });
68
- * });
69
- * }
74
+ * ```js
75
+ * hook_handle_error: (error, req, res, next) => {
76
+ * if (error.status === 404)
77
+ * // If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
78
+ * res.render('errors/404');
79
+ * else
80
+ * // For other errors, unknown error screen (views/error/500.hbs) is displayed.
81
+ * res.render('error/500');
82
+ * },
83
+ * ```
70
84
  */
71
- error_handler: error => {
72
- console.error(`An error has occurred. Error message: ${error.message}`);
73
- }
85
+ hook_handle_error: (error, req, res, next) => {
86
+ if (error.status === 404)
87
+ res.status(404).render('errors/404', {isErrorPage: true});
88
+ else
89
+ res.status(500).render('errors/500', {isErrorPage: true});
90
+ },
74
91
  }