express-sweet 3.0.2 → 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 +224 -418
- package/LICENSE +1 -1
- package/README.md +211 -1026
- package/dist/build.cjs +37 -72
- package/dist/build.mjs +37 -72
- package/package.json +50 -64
- 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 +7 -52
- 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 +19 -12
- 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 +34 -3
- package/types/{interfaces/BasicConfig.d.ts → types/AppConfig.d.ts} +18 -25
- package/types/{interfaces → types}/AuthenticationConfig.d.ts +10 -11
- package/types/{interfaces → types}/DatabaseConfig.d.ts +1 -1
- package/types/{interfaces → types}/LoggingConfig.d.ts +0 -1
- package/types/types/UploadConfig.d.ts +72 -0
- package/types/{interfaces → types}/ViewConfig.d.ts +1 -2
- package/types/{interfaces → types}/index.d.ts +7 -4
- package/types/utils/index.d.ts +7 -4
- package/types/utils/loadAppConfig.d.ts +17 -0
- package/types/utils/loadAuthenticationConfig.d.ts +1 -1
- package/types/utils/loadLoggingConfig.d.ts +1 -1
- package/types/utils/loadUploadConfig.d.ts +20 -0
- package/types/utils/loadViewConfig.d.ts +1 -1
- package/configuration_sample/cjs/authentication.js +0 -138
- package/configuration_sample/cjs/config.js +0 -91
- package/configuration_sample/cjs/database.js +0 -121
- package/configuration_sample/cjs/logging.js +0 -41
- package/configuration_sample/cjs/view.js +0 -54
- package/configuration_sample/esm/authentication.js +0 -136
- package/configuration_sample/esm/config.js +0 -91
- package/configuration_sample/esm/database.js +0 -121
- package/configuration_sample/esm/logging.js +0 -41
- 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/Authentication.d.ts +0 -52
- package/types/middlewares/CORS.d.ts +0 -30
- package/types/middlewares/Environment.d.ts +0 -36
- package/types/middlewares/ErrorHandler.d.ts +0 -34
- package/types/middlewares/Global.d.ts +0 -27
- package/types/middlewares/Http.d.ts +0 -29
- package/types/middlewares/Local.d.ts +0 -42
- package/types/middlewares/View.d.ts +0 -49
- package/types/routing/Router.d.ts +0 -56
- package/types/routing/index.d.ts +0 -37
- 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 -23
- package/types/utils/loadBasicConfig.d.ts +0 -17
|
@@ -2,7 +2,6 @@ import express from 'express';
|
|
|
2
2
|
/**
|
|
3
3
|
* User authentication configuration interface using Passport.js.
|
|
4
4
|
* Defines configuration for user authentication, session management, and security settings.
|
|
5
|
-
* @see {@link https://www.passportjs.org/ | Passport.js}
|
|
6
5
|
* @example
|
|
7
6
|
* ```js
|
|
8
7
|
* // config/authentication.js
|
|
@@ -86,7 +85,7 @@ export default interface AuthenticationConfig {
|
|
|
86
85
|
*/
|
|
87
86
|
success_redirect: string;
|
|
88
87
|
/**
|
|
89
|
-
* URL to redirect
|
|
88
|
+
* URL to redirect to on authentication failure, defaults to `/login`.
|
|
90
89
|
* @type {string|((req: express.Request, res: express.Response) => string)}
|
|
91
90
|
* @example
|
|
92
91
|
* ```js
|
|
@@ -102,10 +101,9 @@ export default interface AuthenticationConfig {
|
|
|
102
101
|
*/
|
|
103
102
|
failure_redirect: string | ((req: express.Request, res: express.Response) => string);
|
|
104
103
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* Note that the user information must include an ID value that can identify the user.
|
|
104
|
+
* Hook called during user authentication.
|
|
105
|
+
* Look up and return the user matching the given credentials, or `null` if not found.
|
|
106
|
+
* The returned object must include an `id` property for session serialization.
|
|
109
107
|
* @type {(username: string, password: string, req: express.Request) => Promise<{[key: string]: any}|null>}
|
|
110
108
|
* @example
|
|
111
109
|
* ```js
|
|
@@ -125,9 +123,9 @@ export default interface AuthenticationConfig {
|
|
|
125
123
|
[key: string]: any;
|
|
126
124
|
} | null>;
|
|
127
125
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* The returned
|
|
126
|
+
* Hook called on each request to deserialize the authenticated user from the session.
|
|
127
|
+
* Look up and return the user data for the given ID.
|
|
128
|
+
* The returned object is set on `req.user` and available in views as `session`.
|
|
131
129
|
* @type {(id: number|string) => Promise<{[key: string]: any}>}
|
|
132
130
|
* @example
|
|
133
131
|
* ```js
|
|
@@ -144,12 +142,13 @@ export default interface AuthenticationConfig {
|
|
|
144
142
|
[key: string]: any;
|
|
145
143
|
}>;
|
|
146
144
|
/**
|
|
147
|
-
* URL
|
|
145
|
+
* URL patterns that bypass authentication. Requests matching any pattern (partial string match
|
|
146
|
+
* or regex match) are allowed without authentication. Defaults to `[]` (all routes protected).
|
|
148
147
|
* @type {(string|RegExp)[]}
|
|
149
148
|
*/
|
|
150
149
|
allow_unauthenticated: (string | RegExp)[];
|
|
151
150
|
/**
|
|
152
|
-
*
|
|
151
|
+
* Session cookie max-age in milliseconds. Defaults to 24 hours (`24 * 3600000`).
|
|
153
152
|
* @type {number}
|
|
154
153
|
*/
|
|
155
154
|
expiration: number;
|
|
@@ -3,7 +3,6 @@ import sequelize from 'sequelize';
|
|
|
3
3
|
* Database configuration interface for Sequelize connections.
|
|
4
4
|
* Defines environment-specific database configurations (development, test, production).
|
|
5
5
|
* Each environment contains Sequelize connection options.
|
|
6
|
-
* @see {@link https://sequelize.org/docs/v6/other-topics/migrations/#configuration | Sequelize Configuration}
|
|
7
6
|
* @example
|
|
8
7
|
* ```js
|
|
9
8
|
* // config/database.js
|
|
@@ -46,6 +45,7 @@ export default interface DatabaseConfig {
|
|
|
46
45
|
* Environment-specific database configuration.
|
|
47
46
|
* Key represents environment name (development, test, production, etc.)
|
|
48
47
|
* Value contains Sequelize connection options for that environment.
|
|
48
|
+
* @type {sequelize.Options}
|
|
49
49
|
*/
|
|
50
50
|
[key: string]: sequelize.Options;
|
|
51
51
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type express from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* File upload configuration interface using Multer.
|
|
4
|
+
* Defines dynamic upload middleware resolution per request based on path and method.
|
|
5
|
+
* @example
|
|
6
|
+
* ```js
|
|
7
|
+
* // config/upload.js
|
|
8
|
+
* export default {
|
|
9
|
+
* enabled: true,
|
|
10
|
+
* resolve_middleware: (req, multer) => {
|
|
11
|
+
* if (req.path === '/api/admin/firms' && req.method === 'POST') {
|
|
12
|
+
* const upload = multer({ storage: multer.memoryStorage() });
|
|
13
|
+
* return upload.fields([
|
|
14
|
+
* { name: 'logo', maxCount: 1 },
|
|
15
|
+
* { name: 'eyecatch', maxCount: 1 }
|
|
16
|
+
* ]);
|
|
17
|
+
* }
|
|
18
|
+
* return null;
|
|
19
|
+
* }
|
|
20
|
+
* };
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export default interface UploadConfig {
|
|
24
|
+
/**
|
|
25
|
+
* Enable file upload middleware, defaults to disabled (false).
|
|
26
|
+
* If config/upload.js doesn't exist, upload middleware won't be applied.
|
|
27
|
+
* @type {boolean}
|
|
28
|
+
*/
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Hook function to dynamically resolve multer middleware based on request.
|
|
32
|
+
* Return a multer middleware instance or null to skip upload handling for the request.
|
|
33
|
+
* @type {(req: express.Request, multer: typeof import('multer')) => Function|null}
|
|
34
|
+
* @example
|
|
35
|
+
* ```js
|
|
36
|
+
* // Single file upload
|
|
37
|
+
* resolve_middleware: (req, multer) => {
|
|
38
|
+
* if (req.path === '/api/user/avatar' && req.method === 'POST') {
|
|
39
|
+
* const upload = multer({ storage: multer.memoryStorage() });
|
|
40
|
+
* return upload.single('avatar');
|
|
41
|
+
* }
|
|
42
|
+
* return null;
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
* @example
|
|
46
|
+
* ```js
|
|
47
|
+
* // Multiple files with same field name
|
|
48
|
+
* resolve_middleware: (req, multer) => {
|
|
49
|
+
* if (req.path === '/api/gallery' && req.method === 'POST') {
|
|
50
|
+
* const upload = multer({ storage: multer.memoryStorage() });
|
|
51
|
+
* return upload.array('photos', 10);
|
|
52
|
+
* }
|
|
53
|
+
* return null;
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
* @example
|
|
57
|
+
* ```js
|
|
58
|
+
* // Multiple file fields
|
|
59
|
+
* resolve_middleware: (req, multer) => {
|
|
60
|
+
* if (req.path === '/api/admin/firms' && req.method === 'POST') {
|
|
61
|
+
* const upload = multer({ storage: multer.memoryStorage() });
|
|
62
|
+
* return upload.fields([
|
|
63
|
+
* { name: 'logo', maxCount: 1 },
|
|
64
|
+
* { name: 'eyecatch', maxCount: 1 }
|
|
65
|
+
* ]);
|
|
66
|
+
* }
|
|
67
|
+
* return null;
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
resolve_middleware: (req: express.Request, multer: typeof import('multer')) => Function | null;
|
|
72
|
+
}
|
|
@@ -2,7 +2,6 @@ import express from 'express';
|
|
|
2
2
|
/**
|
|
3
3
|
* Handlebars view engine configuration interface.
|
|
4
4
|
* Defines configuration for template directories, layouts, partials, and rendering hooks.
|
|
5
|
-
* @see {@link https://handlebarsjs.com/guide/ | Handlebars Guide}
|
|
6
5
|
* @example
|
|
7
6
|
* ```js
|
|
8
7
|
* // config/view.js
|
|
@@ -48,7 +47,7 @@ export default interface ViewConfig {
|
|
|
48
47
|
/**
|
|
49
48
|
* Hook function just before the view is rendered.
|
|
50
49
|
* For example, you can set your own local variables that can be used within the view.
|
|
51
|
-
* @type {(res: express.Response) => Promise<void>|void}
|
|
50
|
+
* @type {(req: express.Request, res: express.Response) => Promise<void>|void}
|
|
52
51
|
* @example
|
|
53
52
|
* ```js
|
|
54
53
|
* // The message set here can be referenced in the view as {{message}}.
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Express Sweet configuration
|
|
2
|
+
* Express Sweet configuration type definitions.
|
|
3
3
|
* Exports all configuration interfaces for type-safe configuration setup.
|
|
4
|
-
* @module interfaces
|
|
5
4
|
*/
|
|
6
5
|
/**
|
|
7
6
|
* User authentication configuration interface using Passport.js
|
|
8
7
|
*/
|
|
9
8
|
export { default as AuthenticationConfig } from './AuthenticationConfig';
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
10
|
+
* Application configuration interface
|
|
12
11
|
*/
|
|
13
|
-
export { default as
|
|
12
|
+
export { default as AppConfig } from './AppConfig';
|
|
14
13
|
/**
|
|
15
14
|
* Database configuration interface for Sequelize connections
|
|
16
15
|
*/
|
|
@@ -23,3 +22,7 @@ export { default as ViewConfig } from './ViewConfig';
|
|
|
23
22
|
* Logging configuration interface using Morgan
|
|
24
23
|
*/
|
|
25
24
|
export { default as LoggingConfig } from './LoggingConfig';
|
|
25
|
+
/**
|
|
26
|
+
* File upload configuration interface using Multer
|
|
27
|
+
*/
|
|
28
|
+
export { default as UploadConfig } from './UploadConfig';
|
package/types/utils/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Provides type checking functions and configuration loading utilities
|
|
5
5
|
* used throughout the Express Sweet framework.
|
|
6
6
|
*
|
|
7
|
-
* @module utils
|
|
8
7
|
* @example
|
|
9
8
|
* ```js
|
|
10
9
|
* // Using type checking utilities
|
|
@@ -23,7 +22,7 @@
|
|
|
23
22
|
* // Using configuration loaders
|
|
24
23
|
* import * as expx from 'express-sweet';
|
|
25
24
|
*
|
|
26
|
-
* const
|
|
25
|
+
* const appConfig = await expx.utils.loadAppConfig();
|
|
27
26
|
* const dbConfig = await expx.utils.loadDatabaseConfig();
|
|
28
27
|
* const authConfig = await expx.utils.loadAuthenticationConfig();
|
|
29
28
|
* const loggingConfig = await expx.utils.loadLoggingConfig();
|
|
@@ -54,9 +53,9 @@ export { default as isString } from './isString';
|
|
|
54
53
|
*/
|
|
55
54
|
export { default as loadAuthenticationConfig } from './loadAuthenticationConfig';
|
|
56
55
|
/**
|
|
57
|
-
* Load
|
|
56
|
+
* Load application configuration from config/config.js
|
|
58
57
|
*/
|
|
59
|
-
export { default as
|
|
58
|
+
export { default as loadAppConfig } from './loadAppConfig';
|
|
60
59
|
/**
|
|
61
60
|
* Load database configuration from config/database.js
|
|
62
61
|
*/
|
|
@@ -69,3 +68,7 @@ export { default as loadViewConfig } from './loadViewConfig';
|
|
|
69
68
|
* Load logging configuration from config/logging.js
|
|
70
69
|
*/
|
|
71
70
|
export { default as loadLoggingConfig } from './loadLoggingConfig';
|
|
71
|
+
/**
|
|
72
|
+
* Load upload configuration from config/upload.js
|
|
73
|
+
*/
|
|
74
|
+
export { default as loadUploadConfig } from './loadUploadConfig';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import AppConfig from '~/types/AppConfig';
|
|
2
|
+
/**
|
|
3
|
+
* Load application configuration from config/config.js file.
|
|
4
|
+
* Returns default configuration if config file doesn't exist.
|
|
5
|
+
* @returns {Promise<AppConfig>} The loaded application configuration with defaults
|
|
6
|
+
* @example
|
|
7
|
+
* ```js
|
|
8
|
+
* import loadAppConfig from '~/utils/loadAppConfig';
|
|
9
|
+
*
|
|
10
|
+
* const config = await loadAppConfig();
|
|
11
|
+
* console.log(config.cors_enabled); // false (default)
|
|
12
|
+
* console.log(config.max_body_size); // '100kb' (default)
|
|
13
|
+
* console.log(config.router_dir); // '/path/to/app/routes' (default)
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare const _default: () => Promise<AppConfig>;
|
|
17
|
+
export default _default;
|
|
@@ -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.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type UploadConfig from '~/types/UploadConfig';
|
|
2
|
+
/**
|
|
3
|
+
* Load upload configuration from config/upload.js file.
|
|
4
|
+
* Returns default configuration if config file doesn't exist.
|
|
5
|
+
*
|
|
6
|
+
* @returns {Promise<UploadConfig>} The loaded upload configuration with defaults
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import loadUploadConfig from '~/utils/loadUploadConfig';
|
|
11
|
+
*
|
|
12
|
+
* const config = await loadUploadConfig();
|
|
13
|
+
* if (config.enabled) {
|
|
14
|
+
* const middleware = config.resolve_middleware(req, multer);
|
|
15
|
+
* // Apply middleware...
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare const _default: () => Promise<UploadConfig>;
|
|
20
|
+
export default _default;
|
|
@@ -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,91 +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 invalid (false).
|
|
15
|
-
* @type {{enabled: 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 default value is the referrer's origin (eg https://example.com).
|
|
41
|
-
* @type {(baseUrl: string): string}
|
|
42
|
-
* @example
|
|
43
|
-
* ```js
|
|
44
|
-
* rewrite_base_url: baseUrl => {
|
|
45
|
-
* return `${baseUrl}/admin`;
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
rewrite_base_url: baseUrl => {
|
|
50
|
-
return baseUrl;
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
/**
|
|
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}
|
|
73
|
-
* @example
|
|
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
|
-
* ```
|
|
84
|
-
*/
|
|
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
|
-
},
|
|
91
|
-
}
|
|
@@ -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
|
-
}
|