express-sweet 4.0.0 → 5.0.0
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 +209 -397
- package/LICENSE +1 -1
- package/README.md +210 -1174
- package/dist/build.cjs +32 -73
- package/dist/build.mjs +32 -73
- package/package.json +45 -61
- package/screenshots/avatar.png +0 -0
- package/screenshots/edit-profile.png +0 -0
- package/screenshots/hero-banner.png +0 -0
- package/screenshots/home.png +0 -0
- package/screenshots/mount-flow.mmd +11 -0
- package/screenshots/mount-flow.png +0 -0
- package/screenshots/new-person.png +0 -0
- package/screenshots/people.png +0 -0
- package/screenshots/sign-in.png +0 -0
- package/types/database/DatabaseManager.d.ts +15 -10
- package/types/database/Model.d.ts +29 -43
- package/types/database/index.d.ts +0 -1
- package/types/database/loadModels.d.ts +7 -13
- package/types/helpers/array.d.ts +21 -0
- package/types/helpers/comparison.d.ts +217 -0
- package/types/helpers/date.d.ts +20 -0
- package/types/helpers/html.d.ts +35 -0
- package/types/{handlebars_helpers → helpers}/index.d.ts +0 -2
- package/types/helpers/layouts.d.ts +29 -0
- package/types/helpers/math.d.ts +85 -0
- package/types/helpers/number.d.ts +19 -0
- package/types/helpers/object.d.ts +28 -0
- package/types/helpers/string.d.ts +45 -0
- package/types/index.d.ts +6 -9
- package/types/middleware/auth.d.ts +186 -0
- package/types/middleware/cors.d.ts +19 -0
- package/types/middleware/env.d.ts +24 -0
- package/types/middleware/error.d.ts +26 -0
- package/types/middleware/globals.d.ts +13 -0
- package/types/{middlewares → middleware}/index.d.ts +12 -13
- package/types/middleware/locals.d.ts +33 -0
- package/types/middleware/parser.d.ts +30 -0
- package/types/middleware/router.d.ts +31 -0
- package/types/middleware/views.d.ts +37 -0
- package/types/mount.d.ts +1 -2
- package/types/{interfaces → types}/AppConfig.d.ts +11 -19
- package/types/{interfaces → types}/AuthenticationConfig.d.ts +10 -11
- package/types/{interfaces → types}/DatabaseConfig.d.ts +0 -1
- package/types/{interfaces → types}/LoggingConfig.d.ts +0 -1
- package/types/{interfaces → types}/UploadConfig.d.ts +0 -1
- package/types/{interfaces → types}/ViewConfig.d.ts +1 -2
- package/types/{interfaces → types}/index.d.ts +1 -2
- package/types/utils/index.d.ts +0 -1
- package/types/utils/loadAppConfig.d.ts +1 -1
- package/types/utils/loadAuthenticationConfig.d.ts +1 -1
- package/types/utils/loadLoggingConfig.d.ts +1 -1
- package/types/utils/loadUploadConfig.d.ts +1 -1
- package/types/utils/loadViewConfig.d.ts +1 -1
- package/configuration_sample/cjs/authentication.js +0 -138
- package/configuration_sample/cjs/config.js +0 -92
- package/configuration_sample/cjs/database.js +0 -121
- package/configuration_sample/cjs/logging.js +0 -41
- package/configuration_sample/cjs/upload.js +0 -91
- package/configuration_sample/cjs/view.js +0 -54
- package/configuration_sample/esm/authentication.js +0 -136
- package/configuration_sample/esm/config.js +0 -92
- package/configuration_sample/esm/database.js +0 -121
- package/configuration_sample/esm/logging.js +0 -41
- package/configuration_sample/esm/upload.js +0 -91
- package/configuration_sample/esm/view.js +0 -54
- package/screencaps/belongs-to-many.png +0 -0
- package/screencaps/belongs-to.png +0 -0
- package/screencaps/demonstration.webp +0 -0
- package/screencaps/has-many.png +0 -0
- package/screencaps/has-one.png +0 -0
- package/types/handlebars_helpers/array.d.ts +0 -22
- package/types/handlebars_helpers/comparison.d.ts +0 -222
- package/types/handlebars_helpers/date.d.ts +0 -19
- package/types/handlebars_helpers/html.d.ts +0 -31
- package/types/handlebars_helpers/layouts.d.ts +0 -25
- package/types/handlebars_helpers/math.d.ts +0 -74
- package/types/handlebars_helpers/number.d.ts +0 -18
- package/types/handlebars_helpers/object.d.ts +0 -21
- package/types/handlebars_helpers/string.d.ts +0 -45
- package/types/middlewares/corsPolicy.d.ts +0 -28
- package/types/middlewares/envLoader.d.ts +0 -34
- package/types/middlewares/errorHandler.d.ts +0 -32
- package/types/middlewares/globalVars.d.ts +0 -25
- package/types/middlewares/localVars.d.ts +0 -44
- package/types/middlewares/passportAuth.d.ts +0 -15
- package/types/middlewares/requestParser.d.ts +0 -27
- package/types/middlewares/routeMapper.d.ts +0 -54
- package/types/middlewares/viewEngine.d.ts +0 -49
- package/types/services/Authentication.d.ts +0 -95
- package/types/services/index.d.ts +0 -33
- package/types/types/global.d.ts +0 -38
- package/types/utils/Types.d.ts +0 -29
package/types/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import AuthenticationConfig from '~/
|
|
1
|
+
import AuthenticationConfig from '~/types/AuthenticationConfig';
|
|
2
2
|
/**
|
|
3
3
|
* Load authentication configuration from config/authentication.js file.
|
|
4
4
|
* Returns default authentication configuration if config file doesn't exist.
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
// const UserModel = require('../models/UserModel');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* User authentication configuration interface.
|
|
5
|
-
*/
|
|
6
|
-
module.exports = {
|
|
7
|
-
/**
|
|
8
|
-
* Enable user authentication, defaults to disabled (false).
|
|
9
|
-
* @type {boolean}
|
|
10
|
-
*/
|
|
11
|
-
enabled: true,
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The session store instance, defaults to a new MemoryStore(memory) instance.
|
|
15
|
-
* @type {'memory|redis'}
|
|
16
|
-
*/
|
|
17
|
-
session_store: 'memory',
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The name of the session ID cookie to set in the response (and read from in the request).
|
|
21
|
-
* The default value is 'connect.sid'.
|
|
22
|
-
* @type {string|undefined}
|
|
23
|
-
*/
|
|
24
|
-
cookie_name: 'connect.sid',
|
|
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
|
-
|
|
40
|
-
/**
|
|
41
|
-
* If the session is stored in "redis", this field is required and should be set to the hostname of the Redis server.
|
|
42
|
-
* For example, to connect to redis on localhost on port 6379, set "redis://localhost:6379".
|
|
43
|
-
* To connect to a different host or port, use a connection string in the format "redis[s]://[[username][:password]@][host][:port][/db-number]".
|
|
44
|
-
* For example, "redis://alice:foobared@awesome.redis.server:6380".
|
|
45
|
-
* @type {string|undefined}
|
|
46
|
-
*/
|
|
47
|
-
redis_host: undefined,
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Authentication user ID field name, defaults to `username`.
|
|
51
|
-
* @type {string}
|
|
52
|
-
*/
|
|
53
|
-
username: 'email',
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Authentication password field name, defaults to `password`.
|
|
57
|
-
* @type {string}
|
|
58
|
-
*/
|
|
59
|
-
password: 'password',
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* URL to redirect after successful authentication, defaults to `/`.
|
|
63
|
-
* @type {string}
|
|
64
|
-
*/
|
|
65
|
-
success_redirect: '/',
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* URL to redirect after log off, defaults to `/login`.
|
|
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
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
failure_redirect: '/login',
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* This hook is called when authenticating a user.
|
|
86
|
-
* Please find the user information that owns the credentials based on the user name and password you received and return it.
|
|
87
|
-
* If the user who owns the credentials cannot be found, return null.
|
|
88
|
-
*
|
|
89
|
-
* Note that the user information must include an ID value that can identify the user.
|
|
90
|
-
*
|
|
91
|
-
* @type {(username: string, password: string, req: express.Request) => Promise<{[key: string]: any}|null>}
|
|
92
|
-
*/
|
|
93
|
-
authenticate_user: async (username, password, req) => {
|
|
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
|
-
};
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* This hook is called when user authentication is successful.
|
|
106
|
-
* Please search and return the authenticated user information to be set in the session based on the user ID of the parameter.
|
|
107
|
-
* The returned data will be set in the req.user property and the view's session variable.
|
|
108
|
-
*
|
|
109
|
-
* @type {(id: number|string) => Promise<{[key: string]: any}>}
|
|
110
|
-
*/
|
|
111
|
-
subscribe_user: async (id) => {
|
|
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
|
-
};
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* URL without authentication. If the URL described in the access URL partially matches, authentication will not be performed, defaults to none.
|
|
125
|
-
* @type {(string|RegExp)[]}
|
|
126
|
-
*/
|
|
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
|
-
],
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Authenticated user session expiration, defaults to 24 hours (24 * 3600000).
|
|
135
|
-
* @type {number}
|
|
136
|
-
*/
|
|
137
|
-
expiration: 24 * 3600000,
|
|
138
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* EXPRESS SWEET basic configuration interface.
|
|
5
|
-
*/
|
|
6
|
-
module.exports = {
|
|
7
|
-
/**
|
|
8
|
-
* Environment variable file (.env) path, defaults to none (undefined).
|
|
9
|
-
* @type {string}
|
|
10
|
-
*/
|
|
11
|
-
env_path: '.env',
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* CORS permission, defaults to disabled (false).
|
|
15
|
-
* @type {boolean}
|
|
16
|
-
*/
|
|
17
|
-
cors_enabled: true,
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Maximum body size you can request, defaults to `100kb`.
|
|
21
|
-
* @type {string|number}
|
|
22
|
-
*/
|
|
23
|
-
max_body_size: '100mb',
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Absolute path to the router directory, defaults to `<application root directory>/routes`.
|
|
27
|
-
* @type {string}
|
|
28
|
-
*/
|
|
29
|
-
router_dir: path.join(process.cwd(), 'routes'),
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The endpoint to run when the root URL is requested, defaults to none (undefined).
|
|
33
|
-
* @type {string}
|
|
34
|
-
*/
|
|
35
|
-
default_router: '/home',
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* This is a hook that rewrites the base URL.
|
|
39
|
-
* If you want to rewrite the app.locals.baseUrl property and the view's baseUrl variable, use this hook to return a new base URL.
|
|
40
|
-
* The baseUrl parameter may be undefined if URL construction fails (e.g., invalid Host header).
|
|
41
|
-
* @type {(baseUrl: string | undefined) => string | undefined}
|
|
42
|
-
* @example
|
|
43
|
-
* ```js
|
|
44
|
-
* rewrite_base_url: baseUrl => {
|
|
45
|
-
* if (!baseUrl) return 'http://localhost:3000'; // Fallback for undefined
|
|
46
|
-
* return `${baseUrl}/admin`;
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
rewrite_base_url: baseUrl => {
|
|
51
|
-
return baseUrl;
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* How to determine if it is an ajax request.
|
|
56
|
-
* The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
|
|
57
|
-
* 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)".
|
|
58
|
-
* @type {(req: express.Request) => boolean}
|
|
59
|
-
* @example
|
|
60
|
-
* ```js
|
|
61
|
-
* is_ajax: req => {
|
|
62
|
-
* // If the request URL begins with /api, it is assumed to be Ajax.
|
|
63
|
-
* return /^\/api/.test(req.path);
|
|
64
|
-
* // return !!req.xhr;
|
|
65
|
-
* }
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
is_ajax: req => !!req.xhr,
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Hooks the default behavior on request errors.
|
|
72
|
-
* If unset, simply returns an error HTTP status. (<code>res.status(error.status||500).end();</code>)
|
|
73
|
-
* @type {(error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
|
|
74
|
-
* @example
|
|
75
|
-
* ```js
|
|
76
|
-
* hook_handle_error: (error, req, res, next) => {
|
|
77
|
-
* if (error.status === 404)
|
|
78
|
-
* // If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
|
|
79
|
-
* res.render('errors/404');
|
|
80
|
-
* else
|
|
81
|
-
* // For other errors, unknown error screen (views/error/500.hbs) is displayed.
|
|
82
|
-
* res.render('error/500');
|
|
83
|
-
* },
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
hook_handle_error: (error, req, res, next) => {
|
|
87
|
-
if (error.status === 404)
|
|
88
|
-
res.status(404).render('errors/404', {isErrorPage: true});
|
|
89
|
-
else
|
|
90
|
-
res.status(500).render('errors/500', {isErrorPage: true});
|
|
91
|
-
},
|
|
92
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
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
|
-
* }
|
|
48
|
-
*/
|
|
49
|
-
module.exports = {
|
|
50
|
-
// Development environment configuration
|
|
51
|
-
development: {
|
|
52
|
-
username: 'root',
|
|
53
|
-
password: 'password',
|
|
54
|
-
database: 'sample_db',
|
|
55
|
-
host: 'localhost',
|
|
56
|
-
port: undefined,
|
|
57
|
-
dialect: 'mariadb',
|
|
58
|
-
timezone: '+09:00',
|
|
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
|
-
// }
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
// Test environment configuration
|
|
75
|
-
test: {
|
|
76
|
-
username: 'root',
|
|
77
|
-
password: 'password',
|
|
78
|
-
database: 'sample_db',
|
|
79
|
-
host: 'localhost',
|
|
80
|
-
port: undefined,
|
|
81
|
-
dialect: 'mariadb',
|
|
82
|
-
timezone: '+09:00',
|
|
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
|
-
// }
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
// Production environment configuration
|
|
99
|
-
production: {
|
|
100
|
-
username: 'root',
|
|
101
|
-
password: 'password',
|
|
102
|
-
database: 'sample_db',
|
|
103
|
-
host: 'localhost',
|
|
104
|
-
port: undefined,
|
|
105
|
-
dialect: 'mariadb',
|
|
106
|
-
timezone: '+09:00',
|
|
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
|
-
// }
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File upload configuration interface using Multer.
|
|
3
|
-
*/
|
|
4
|
-
module.exports = {
|
|
5
|
-
/**
|
|
6
|
-
* Enable file upload middleware, defaults to disabled (false).
|
|
7
|
-
* @type {boolean}
|
|
8
|
-
* @example
|
|
9
|
-
* ```js
|
|
10
|
-
* // Enable file upload middleware
|
|
11
|
-
* enabled: true,
|
|
12
|
-
*
|
|
13
|
-
* // Disable file upload middleware
|
|
14
|
-
* enabled: false,
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
enabled: false,
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Hook function to dynamically resolve multer middleware based on request.
|
|
21
|
-
* Return a multer middleware instance or null to skip upload handling for the request.
|
|
22
|
-
* @type {(req: express.Request, multer: typeof import('multer')) => Function|null}
|
|
23
|
-
* @example
|
|
24
|
-
* ```js
|
|
25
|
-
* // Single file upload
|
|
26
|
-
* resolve_middleware: (req, multer) => {
|
|
27
|
-
* if (req.path === '/api/user/avatar' && req.method === 'POST') {
|
|
28
|
-
* const upload = multer({ storage: multer.memoryStorage() });
|
|
29
|
-
* return upload.single('avatar');
|
|
30
|
-
* }
|
|
31
|
-
* return null;
|
|
32
|
-
* },
|
|
33
|
-
* ```
|
|
34
|
-
* @example
|
|
35
|
-
* ```js
|
|
36
|
-
* // Multiple files with same field name
|
|
37
|
-
* resolve_middleware: (req, multer) => {
|
|
38
|
-
* if (req.path === '/api/gallery' && req.method === 'POST') {
|
|
39
|
-
* const upload = multer({ storage: multer.memoryStorage() });
|
|
40
|
-
* return upload.array('photos', 10);
|
|
41
|
-
* }
|
|
42
|
-
* return null;
|
|
43
|
-
* },
|
|
44
|
-
* ```
|
|
45
|
-
* @example
|
|
46
|
-
* ```js
|
|
47
|
-
* // Multiple file fields
|
|
48
|
-
* resolve_middleware: (req, multer) => {
|
|
49
|
-
* if (req.path === '/api/admin/firms' && req.method === 'POST') {
|
|
50
|
-
* const upload = multer({ storage: multer.memoryStorage() });
|
|
51
|
-
* return upload.fields([
|
|
52
|
-
* { name: 'logo', maxCount: 1 },
|
|
53
|
-
* { name: 'eyecatch', maxCount: 1 }
|
|
54
|
-
* ]);
|
|
55
|
-
* }
|
|
56
|
-
* return null;
|
|
57
|
-
* },
|
|
58
|
-
* ```
|
|
59
|
-
* @example
|
|
60
|
-
* ```js
|
|
61
|
-
* // With disk storage and file filtering
|
|
62
|
-
* resolve_middleware: (req, multer) => {
|
|
63
|
-
* if (req.path === '/api/documents' && req.method === 'POST') {
|
|
64
|
-
* const storage = multer.diskStorage({
|
|
65
|
-
* destination: (req, file, cb) => {
|
|
66
|
-
* cb(null, 'uploads/');
|
|
67
|
-
* },
|
|
68
|
-
* filename: (req, file, cb) => {
|
|
69
|
-
* cb(null, `${Date.now()}-${file.originalname}`);
|
|
70
|
-
* }
|
|
71
|
-
* });
|
|
72
|
-
* const upload = multer({
|
|
73
|
-
* storage,
|
|
74
|
-
* fileFilter: (req, file, cb) => {
|
|
75
|
-
* // Accept only PDF files
|
|
76
|
-
* if (file.mimetype === 'application/pdf') {
|
|
77
|
-
* cb(null, true);
|
|
78
|
-
* } else {
|
|
79
|
-
* cb(new Error('Only PDF files are allowed'));
|
|
80
|
-
* }
|
|
81
|
-
* },
|
|
82
|
-
* limits: { fileSize: 5 * 1024 * 1024 } // 5MB limit
|
|
83
|
-
* });
|
|
84
|
-
* return upload.single('document');
|
|
85
|
-
* }
|
|
86
|
-
* return null;
|
|
87
|
-
* },
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
resolve_middleware: undefined
|
|
91
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* View's configuration interface.
|
|
5
|
-
*/
|
|
6
|
-
module.exports = {
|
|
7
|
-
/**
|
|
8
|
-
* Absolute path to the directory where the view files are located, defaults to `<application root directory>/views`.
|
|
9
|
-
* @type {string}
|
|
10
|
-
*/
|
|
11
|
-
views_dir: path.join(process.cwd(), 'views'),
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Path to partials templates, one or several directories, defaults to `<application root directory>/views/partials`.
|
|
15
|
-
* @type {string|string[]}
|
|
16
|
-
*/
|
|
17
|
-
partials_dir: path.join(process.cwd(), 'views/partials'),
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Path to layout templates, defaults to `<application root directory>/views/layout`.
|
|
21
|
-
* @type {string}
|
|
22
|
-
*/
|
|
23
|
-
layouts_dir: path.join(process.cwd(), 'views/layout'),
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Absolute path to default layout template. defaults to `<application root directory>/views/layout/default.hbs`.
|
|
27
|
-
* @type {string}
|
|
28
|
-
*/
|
|
29
|
-
default_layout: path.join(process.cwd(), 'views/layout/default.hbs'),
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Extension for templates & partials, defaults to `.hbs`,
|
|
33
|
-
* @type {string}
|
|
34
|
-
*/
|
|
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
|
-
}
|
|
54
|
-
}
|