express-sweet-generator 2.0.23 → 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.
package/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  [EXPRESS SWEET](https://www.npmjs.com/package/express-sweet)'s application generator.
4
4
 
5
- A comprehensive list of changes in each version may be found in the [CHANGELOG](CHANGELOG.md).
6
-
7
5
  ## Installation
8
6
 
9
7
  ```bash
@@ -199,62 +197,105 @@ The generated application has the following directory structure:
199
197
 
200
198
  ```
201
199
  .
202
- ├── .env # Environment variables
203
- ├── app.js # Main application file
204
- ├── ecosystem.config.js # PM2 configuration
205
- ├── nginx.sample.conf # Sample Nginx configuration
200
+ ├── .env # Environment variables configuration
201
+ ├── app.js # Main application entry point
202
+ ├── ecosystem.config.js # PM2 process manager configuration
203
+ ├── nginx.sample.conf # Sample Nginx reverse proxy configuration
206
204
  ├── package.json # Node.js dependencies and scripts
207
205
  ├── bin
208
206
  │ └── www # Application startup script
209
- ├── client # Frontend application
207
+ ├── client # Frontend application directory
210
208
  │ ├── package.json # Frontend dependencies
211
- │ ├── webpack.config.js # Webpack configuration
209
+ │ ├── webpack.config.js # Webpack bundler configuration
212
210
  │ └── src # Frontend source code
213
- ├── config # Application configuration
214
- │ ├── authentication.js # Authentication settings
215
- │ ├── config.js # General configuration
216
- │ ├── database.js # Database configuration
217
- │ └── view.js # View engine configuration
211
+ ├── config # Application configuration files
212
+ │ ├── authentication.js # Authentication and session settings
213
+ │ ├── config.js # Core application configuration
214
+ │ ├── database.js # Database connection settings
215
+ │ ├── logging.js # HTTP request logging configuration
216
+ │ └── view.js # Template engine configuration
218
217
  ├── errors # Custom error classes
219
- │ └── NotFoundError.js # 404 error handler
218
+ │ └── NotFoundError.js # Custom error definitions
220
219
  ├── middlewares # Express middlewares
221
220
  │ └── checkValidationResult.js # Validation middleware
222
- ├── models # Sequelize models
223
- │ ├── BookModel.js # Book model
224
- │ ├── CommentModel.js # Comment model
225
- │ ├── ProfileModel.js # Profile model
226
- │ └── UserModel.js # User model
227
- ├── public # Static assets
228
- │ ├── build # Built frontend assets
221
+ ├── models # Database models (Sequelize ORM)
222
+ │ ├── BookModel.js # Book entity model
223
+ │ ├── CommentModel.js # Comment entity model
224
+ │ ├── ProfileModel.js # User profile model
225
+ │ └── UserModel.js # User entity model
226
+ ├── public # Static assets directory
227
+ │ ├── build # Compiled frontend assets
229
228
  │ └── upload # User uploaded files
230
- ├── routes # Express routes
231
- │ ├── login.js # Login routes
232
- │ ├── profile.js # Profile routes
233
- │ ├── users.js # User routes
234
- │ └── api # API routes
229
+ ├── routes # Express route definitions
230
+ │ ├── login.js # Authentication routes
231
+ │ ├── profile.js # Profile management routes
232
+ │ ├── users.js # User management routes
233
+ │ └── api # API endpoints
235
234
  │ ├── profile.js # Profile API routes
236
235
  │ └── users.js # User API routes
237
- ├── shared # Shared utilities
236
+ ├── shared # Shared utilities and helpers
238
237
  │ └── isEmpty.js # Utility functions
239
- ├── validators # Custom validators
238
+ ├── validators # Custom validation functions
240
239
  │ └── isValidImageDataUrl.js # Image validation
241
- └── views # Handlebars templates
240
+ └── views # Handlebars template files
242
241
  ├── error.hbs # Error page template
243
242
  ├── login.hbs # Login page template
244
- ├── layout
245
- │ └── default.hbs # Default layout template
246
- ├── partials
247
- │ └── .gitkeep # Partial templates directory
243
+ ├── layout # Layout templates
244
+ │ └── default.hbs # Default page layout
245
+ ├── partials # Reusable template components
246
+ │ └── .gitkeep # Placeholder for partial templates
248
247
  ├── users
249
- │ └── index.hbs # Users index template
248
+ │ └── index.hbs # Users listing template
250
249
  ├── profile
251
- │ ├── show.hbs # Profile show template
252
- │ └── edit.hbs # Profile edit template
250
+ │ ├── show.hbs # Profile display template
251
+ │ └── edit.hbs # Profile editing template
253
252
  └── errors
254
253
  ├── 404.hbs # 404 error template
255
254
  └── 500.hbs # 500 error template
256
255
  ```
257
256
 
257
+ ### Key Directories Explained
258
+
259
+ **Configuration (`config/`)**
260
+ Contains all application settings divided by functionality. Modify these files to customize database connections, authentication behavior, view rendering, and logging.
261
+
262
+ **Models (`models/`)**
263
+ Database entities using Sequelize ORM. Each model represents a database table and defines the schema, relationships, and business logic for that entity.
264
+
265
+ **Routes (`routes/`)**
266
+ URL endpoint handlers organized by feature. The file structure automatically maps to URL paths - for example, `routes/api/users.js` handles requests to `/api/users`.
267
+
268
+ **Views (`views/`)**
269
+ Handlebars templates for rendering HTML pages. The `layout/` directory contains base templates, while `partials/` holds reusable components.
270
+
271
+ **Public (`public/`)**
272
+ Static files served directly by the web server. The `build/` directory contains compiled frontend assets, while `upload/` stores user-generated content.
273
+
274
+ ## Getting Started with Your Generated App
275
+
276
+ Once your application is generated and running, you can:
277
+
278
+ 1. **Explore the Features**: Visit the main framework documentation to understand routing, models, authentication, and view system
279
+ 2. **Customize Configuration**: Modify files in the `config/` directory to suit your needs
280
+ 3. **Add New Models**: Create additional models in the `models/` directory following the existing patterns
281
+ 4. **Build Routes**: Add new routes in the `routes/` directory for your application logic
282
+ 5. **Create Views**: Design templates in the `views/` directory using Handlebars
283
+
284
+ For detailed tutorials and advanced usage, visit the [EXPRESS SWEET Documentation](https://takuya-motoshima.github.io/express-sweet/).
285
+
286
+ ## API Reference
287
+
288
+ For comprehensive documentation on using the generated application, refer to the **[EXPRESS SWEET Documentation](https://takuya-motoshima.github.io/express-sweet/)**.
289
+
290
+ The complete API reference includes:
291
+
292
+ - **[Database](https://takuya-motoshima.github.io/express-sweet/modules/database.html)**: Model classes and database management
293
+ - **[Authentication](https://takuya-motoshima.github.io/express-sweet/classes/services.Authentication.html)**: User authentication and session management
294
+ - **[Routing](https://takuya-motoshima.github.io/express-sweet/modules/routing.html)**: Advanced routing functionality
295
+ - **[Handlebars Helpers](https://takuya-motoshima.github.io/express-sweet/modules/handlebars_helpers.html)**: Template helpers for views
296
+ - **[Configuration](https://takuya-motoshima.github.io/express-sweet/modules/interfaces.html)**: All configuration interfaces
297
+ - **[Middlewares](https://takuya-motoshima.github.io/express-sweet/modules/middlewares.html)**: Built-in middleware components
298
+
258
299
  ## Command Options
259
300
 
260
301
  ```bash
@@ -268,6 +309,10 @@ Options:
268
309
  -h, --help Display help for command
269
310
  ```
270
311
 
312
+ ## Release Notes
313
+
314
+ All changes and version history can be found in the [CHANGELOG.md](CHANGELOG.md).
315
+
271
316
  ## Author
272
317
 
273
318
  **Takuya Motoshima**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet-generator",
3
- "version": "2.0.23",
3
+ "version": "3.0.1",
4
4
  "description": "EXPRESS SWEET application generator.",
5
5
  "main": "bin/express-sweet-cli.js",
6
6
  "files": [
@@ -68,6 +68,7 @@ module.exports = {
68
68
  * URL to redirect after log off, defaults to `/login`.
69
69
  * @type {string|((req: express.Request, res: express.Response) => string)}
70
70
  * @example
71
+ * ```js
71
72
  * // Set the URL to redirect to in case of login failure as a string.
72
73
  * failure_redirect: '/login',
73
74
  *
@@ -76,6 +77,7 @@ module.exports = {
76
77
  * // If the role stored in the cookie is admin, redirect to the admin login screen.
77
78
  * return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
78
79
  * },
80
+ * ```
79
81
  */
80
82
  failure_redirect: '/login',
81
83
 
@@ -40,9 +40,11 @@ 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;
@@ -54,11 +56,13 @@ module.exports = {
54
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)".
55
57
  * @type {(req: express.Request) => boolean}
56
58
  * @example
59
+ * ```js
57
60
  * is_ajax: req => {
58
61
  * // If the request URL begins with /api, it is assumed to be Ajax.
59
62
  * return /^\/api/.test(req.path);
60
63
  * // return !!req.xhr;
61
64
  * }
65
+ * ```
62
66
  */
63
67
  is_ajax: req => !!req.xhr,
64
68
 
@@ -67,6 +71,7 @@ module.exports = {
67
71
  * If unset, simply returns an error HTTP status. (<code>res.status(error.status||500).end();</code>)
68
72
  * @type {(error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
69
73
  * @example
74
+ * ```js
70
75
  * hook_handle_error: (error, req, res, next) => {
71
76
  * if (error.status === 404)
72
77
  * // If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
@@ -75,6 +80,7 @@ module.exports = {
75
80
  * // For other errors, unknown error screen (views/error/500.hbs) is displayed.
76
81
  * res.render('error/500');
77
82
  * },
83
+ * ```
78
84
  */
79
85
  hook_handle_error: (error, req, res, next) => {
80
86
  if (error.status === 404)
@@ -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,37 @@
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: undefined
37
+ }
@@ -39,10 +39,12 @@ module.exports = {
39
39
  * For example, you can set your own local variables that can be used within the view.
40
40
  * @type {(res: express.Response) => Promise<void>|void}
41
41
  * @example
42
+ * ```js
42
43
  * // The message set here can be referenced in the view as {{message}}.
43
44
  * beforeRender: (req, res) => {
44
45
  * res.locals.extra = 'Extra';
45
46
  * }
47
+ * ```
46
48
  */
47
49
  beforeRender: (req, res) => {
48
50
  // Set the initial sidebar state from the cookie, defaulting to 'off'.
@@ -10,7 +10,7 @@
10
10
  "dependencies": {
11
11
  "debug": "~2.6.9",
12
12
  "express": "^4.21.2",
13
- "express-sweet": "^2.0.9",
13
+ "express-sweet": "^3.0.0",
14
14
  "express-validator": "^6.14.2",
15
15
  "http-errors": "~1.6.3",
16
16
  "nodejs-shared": "^1.0.28"
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Checks if a string is empty or contains only whitespace characters.
3
3
  * @param {string|null|false} str The string to check.
4
- * @return {boolean} True if the string is empty or contains only whitespace, false otherwise.
4
+ * @returns {boolean} True if the string is empty or contains only whitespace, false otherwise.
5
5
  */
6
6
  module.exports = str => {
7
7
  if (str == null || str === false)
@@ -3,7 +3,7 @@ const isEmpty = require('../shared/isEmpty');
3
3
  /**
4
4
  * Validates if a value is a valid image Data URL.
5
5
  * @param {string} value The value to validate.
6
- * @return {boolean} True if the value is a valid image Data URL or empty, otherwise throws an error.
6
+ * @returns {boolean} True if the value is a valid image Data URL or empty, otherwise throws an error.
7
7
  * @throws {Error} If the value is not a valid image Data URL format.
8
8
  */
9
9
  module.exports = (value) => {
@@ -14,7 +14,7 @@ export default class extends Api {
14
14
  /**
15
15
  * Updates the user's profile.
16
16
  * @param {FormData} formData The form data containing the updated profile information.
17
- * @return {Promise<object>} The API response.
17
+ * @returns {Promise<object>} The API response.
18
18
  */
19
19
  async updateProfile(formData) {
20
20
  return this.client.put('/', formData);
@@ -14,7 +14,7 @@ export default class extends Api {
14
14
  /**
15
15
  * Logs in a user.
16
16
  * @param {FormData} formData The form data containing the user's login credentials.
17
- * @return {Promise<object>} The API response.
17
+ * @returns {Promise<object>} The API response.
18
18
  */
19
19
  async login(formData) {
20
20
  return this.client.post('login', formData);
@@ -22,7 +22,7 @@ export default class extends Api {
22
22
 
23
23
  /**
24
24
  * Logs out the current user.
25
- * @return {void}
25
+ * @returns {void}
26
26
  */
27
27
  async logout() {
28
28
  location.assign('/api/users/logout');
@@ -31,7 +31,7 @@ export default class extends Api {
31
31
  /**
32
32
  * Creates a new user.
33
33
  * @param {FormData} formData The form data containing the new user's information.
34
- * @return {Promise<object>} The API response.
34
+ * @returns {Promise<object>} The API response.
35
35
  */
36
36
  async createUser(formData) {
37
37
  return this.client.post('/', formData);
@@ -40,7 +40,7 @@ export default class extends Api {
40
40
  /**
41
41
  * Retrieves a user by ID.
42
42
  * @param {number} userId The ID of the user to retrieve.
43
- * @return {Promise<object>} The API response.
43
+ * @returns {Promise<object>} The API response.
44
44
  */
45
45
  async getUser(userId) {
46
46
  return this.client.get(`/${userId}`);
@@ -50,7 +50,7 @@ export default class extends Api {
50
50
  * Updates a user by ID.
51
51
  * @param {number} userId The ID of the user to update.
52
52
  * @param {FormData} formData - The form data containing the updated user information.
53
- * @return {Promise<object>} The API response.
53
+ * @returns {Promise<object>} The API response.
54
54
  */
55
55
  async updateUser(userId, formData) {
56
56
  return this.client.put(`/${userId}`, formData);
@@ -59,7 +59,7 @@ export default class extends Api {
59
59
  /**
60
60
  * Deletes a user by ID.
61
61
  * @param {number} userId The ID of the user to delete.
62
- * @return {Promise<object>} The API response.
62
+ * @returns {Promise<object>} The API response.
63
63
  */
64
64
  async deleteUser(userId) {
65
65
  return this.client.delete(`/${userId}`);
@@ -72,7 +72,7 @@ export default class extends components.Modal {
72
72
  * Render Modal.
73
73
  * @param {'create'|'update'} mode Processing mode.
74
74
  * @param {number|undefined} userId Update User ID.
75
- * @return {string} Modal HTML.
75
+ * @returns {string} Modal HTML.
76
76
  */
77
77
  async render(mode, userId = null) {
78
78
  // In case of update, the target user is retrieved.
@@ -36,7 +36,7 @@ export default class extends components.Api {
36
36
  * Handles API errors.
37
37
  * @param {number} code The HTTP status code.
38
38
  * @param {Error} error The error object.
39
- * @return {void}
39
+ * @returns {void}
40
40
  */
41
41
  errorHook(code, error) {
42
42
  // Check if the error object and request properties exist to avoid runtime errors
@@ -54,7 +54,7 @@ export default class extends components.Datatable {
54
54
  /**
55
55
  * Generates a unique state key for the DataTable.
56
56
  * @param {object} settings DataTables settings object.
57
- * @return {string} The generated state key.
57
+ * @returns {string} The generated state key.
58
58
  */
59
59
  const getStateKey = (settings) => {
60
60
  let stateKey = settings.sTableId;
@@ -93,7 +93,7 @@ export default class extends components.Datatable {
93
93
  /**
94
94
  * Handles AJAX errors.
95
95
  * @param {number} code The HTTP status code of the error.
96
- * @return {void}
96
+ * @returns {void}
97
97
  */
98
98
  ajaxErrorHook(code) {
99
99
  // Log the error details.
@@ -68,6 +68,7 @@ export default {
68
68
  * URL to redirect after log off, defaults to `/login`.
69
69
  * @type {string|((req: express.Request, res: express.Response) => string)}
70
70
  * @example
71
+ * ```js
71
72
  * // Set the URL to redirect to in case of login failure as a string.
72
73
  * failure_redirect: '/login',
73
74
  *
@@ -76,6 +77,7 @@ export default {
76
77
  * // If the role stored in the cookie is admin, redirect to the admin login screen.
77
78
  * return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
78
79
  * },
80
+ * ```
79
81
  */
80
82
  failure_redirect: '/login',
81
83
 
@@ -40,9 +40,11 @@ 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;
@@ -54,11 +56,13 @@ export default {
54
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)".
55
57
  * @type {(req: express.Request) => boolean}
56
58
  * @example
59
+ * ```js
57
60
  * is_ajax: req => {
58
61
  * // If the request URL begins with /api, it is assumed to be Ajax.
59
62
  * return /^\/api/.test(req.path);
60
63
  * // return !!req.xhr;
61
64
  * }
65
+ * ```
62
66
  */
63
67
  is_ajax: req => !!req.xhr,
64
68
 
@@ -67,6 +71,7 @@ export default {
67
71
  * If unset, simply returns an error HTTP status. (<code>res.status(error.status||500).end();</code>)
68
72
  * @type {(error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
69
73
  * @example
74
+ * ```js
70
75
  * hook_handle_error: (error, req, res, next) => {
71
76
  * if (error.status === 404)
72
77
  * // If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
@@ -75,6 +80,7 @@ export default {
75
80
  * // For other errors, unknown error screen (views/error/500.hbs) is displayed.
76
81
  * res.render('error/500');
77
82
  * },
83
+ * ```
78
84
  */
79
85
  hook_handle_error: (error, req, res, next) => {
80
86
  if (error.status === 404)
@@ -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
  export default {
50
+ // Development environment configuration
5
51
  development: {
6
52
  username: 'root',
7
53
  password: 'password',
@@ -10,8 +56,22 @@ export default {
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 @@ export default {
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 @@ export default {
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,37 @@
1
+ /**
2
+ * Logging configuration interface.
3
+ */
4
+ export default {
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: undefined
37
+ }
@@ -39,10 +39,12 @@ export default {
39
39
  * For example, you can set your own local variables that can be used within the view.
40
40
  * @type {(res: express.Response) => Promise<void>|void}
41
41
  * @example
42
+ * ```js
42
43
  * // The message set here can be referenced in the view as {{message}}.
43
44
  * beforeRender: (req, res) => {
44
45
  * res.locals.extra = 'Extra';
45
46
  * }
47
+ * ```
46
48
  */
47
49
  beforeRender: (req, res) => {
48
50
  // Set the initial sidebar state from the cookie, defaulting to 'off'.
@@ -14,7 +14,7 @@
14
14
  "dependencies": {
15
15
  "debug": "~2.6.9",
16
16
  "express": "^4.21.2",
17
- "express-sweet": "^2.0.9",
17
+ "express-sweet": "^3.0.0",
18
18
  "express-validator": "^6.14.2",
19
19
  "http-errors": "~1.6.3",
20
20
  "nodejs-shared": "^1.0.28"
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Checks if a string is empty or contains only whitespace characters.
3
3
  * @param {string|null|false} str The string to check.
4
- * @return {boolean} True if the string is empty or contains only whitespace, false otherwise.
4
+ * @returns {boolean} True if the string is empty or contains only whitespace, false otherwise.
5
5
  */
6
6
  export default str => {
7
7
  if (str == null || str === false)
@@ -3,7 +3,7 @@ import isEmpty from '../shared/isEmpty.js';
3
3
  /**
4
4
  * Validates if a value is a valid image Data URL.
5
5
  * @param {string} value The value to validate.
6
- * @return {boolean} True if the value is a valid image Data URL or empty, otherwise throws an error.
6
+ * @returns {boolean} True if the value is a valid image Data URL or empty, otherwise throws an error.
7
7
  * @throws {Error} If the value is not a valid image Data URL format.
8
8
  */
9
9
  export default value => {