express-sweet 2.0.2 → 2.0.3
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 +51 -7
- package/README.md +2109 -20
- package/configuration_sample/cjs/authentication.js +103 -0
- package/configuration_sample/cjs/config.js +76 -0
- package/configuration_sample/cjs/database.js +35 -0
- package/configuration_sample/cjs/view.js +36 -0
- package/configuration_sample/esm/authentication.js +103 -0
- package/configuration_sample/esm/config.js +76 -0
- package/configuration_sample/esm/database.js +35 -0
- package/configuration_sample/esm/view.js +36 -0
- package/dist/build.cjs +22 -22
- package/dist/build.mjs +22 -22
- package/package.json +8 -11
- 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/database/Database.d.ts +3 -171
- package/types/database/Model.d.ts +9 -6
- package/types/database/loadModels.d.ts +2 -1
- package/types/handlebars_helpers/comparison.d.ts +40 -170
- package/types/handlebars_helpers/index.d.ts +1 -0
- package/types/handlebars_helpers/layouts.d.ts +21 -0
- package/types/handlebars_helpers/math.d.ts +0 -7
- package/types/handlebars_helpers/object.d.ts +2 -2
- package/types/handlebars_helpers/string.d.ts +1 -6
- package/types/interfaces/AuthenticationConfig.d.ts +0 -4
- package/types/interfaces/BasicConfig.d.ts +1 -4
- package/types/interfaces/ViewConfig.d.ts +0 -1
- package/types/middlewares/Authentication.d.ts +3 -1
- package/types/middlewares/CORS.d.ts +3 -1
- package/types/middlewares/Environment.d.ts +3 -3
- package/types/middlewares/ErrorHandler.d.ts +3 -1
- package/types/middlewares/Http.d.ts +3 -1
- package/types/middlewares/Local.d.ts +3 -1
- package/types/middlewares/View.d.ts +6 -2
- package/types/mount.d.ts +3 -2
- package/types/routing/Router.d.ts +3 -1
- package/types/services/Authentication.d.ts +4 -2
- package/types/utils/loadAuthenticationConfig.d.ts +2 -2
- package/types/utils/loadBasicConfig.d.ts +2 -2
- package/types/utils/loadDatabaseConfig.d.ts +2 -2
- package/types/utils/loadViewConfig.d.ts +2 -2
- package/INSTALL-Redis.md +0 -77
- package/QUICK_START.md +0 -149
- package/screencaps/login.jpg +0 -0
- package/screencaps/personal.jpg +0 -0
- package/screencaps/user-editing.jpg +0 -0
- package/screencaps/users.jpg +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declare block race holders in layout.
|
|
3
|
+
* Imported from {@link https://github.com/TryGhost/express-hbs|express-hbs}
|
|
4
|
+
* @example
|
|
5
|
+
* {{{block "pageScripts"}}}
|
|
6
|
+
* @param {string} name Block Name.
|
|
7
|
+
* @param {Handlebars.HelperOptions} options Helper Options.
|
|
8
|
+
* @return {string} String.
|
|
9
|
+
*/
|
|
10
|
+
export declare const block: (this: any, name: string, options: Handlebars.HelperOptions) => any;
|
|
11
|
+
/**
|
|
12
|
+
* Define block content within a page.
|
|
13
|
+
* Imported from {@link https://github.com/TryGhost/express-hbs|express-hbs}
|
|
14
|
+
* @example
|
|
15
|
+
* {{#contentFor "pageScripts"}}
|
|
16
|
+
* CONTENT HERE
|
|
17
|
+
* {{/contentFor}}
|
|
18
|
+
* @param {string} name Block Name.
|
|
19
|
+
* @param {Handlebars.HelperOptions} options Helper Options.
|
|
20
|
+
*/
|
|
21
|
+
export declare const contentFor: (this: any, name: string, options: any) => void;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Calculates the sum of two numbers.
|
|
3
3
|
* @example
|
|
4
|
-
* {{!-- results in: 3 --}}
|
|
5
4
|
* {{add 1 2}}
|
|
6
5
|
* @param {number|string} val1 The first number.
|
|
7
6
|
* @param {number|string} val2 The second number.
|
|
@@ -11,7 +10,6 @@ export declare const add: (val1: number | string, val2: number | string) => numb
|
|
|
11
10
|
/**
|
|
12
11
|
* Calculates the difference of the given values.
|
|
13
12
|
* @example
|
|
14
|
-
* {{!-- results in: 3 --}}
|
|
15
13
|
* {{sub 5 2}}
|
|
16
14
|
* @param {number|string} val1 The first number.
|
|
17
15
|
* @param {number|string} val2 The second number.
|
|
@@ -21,7 +19,6 @@ export declare const sub: (val1: number | string, val2: number | string) => numb
|
|
|
21
19
|
/**
|
|
22
20
|
* Calculate the multiplication of the given values.
|
|
23
21
|
* @example
|
|
24
|
-
* {{!-- results in: 10 --}}
|
|
25
22
|
* {{multiply 5 2}}
|
|
26
23
|
* @param {number|string} val1 The first number.
|
|
27
24
|
* @param {number|string} val2 The second number.
|
|
@@ -31,7 +28,6 @@ export declare const multiply: (val1: number | string, val2: number | string) =>
|
|
|
31
28
|
/**
|
|
32
29
|
* Compute the division of the given values.
|
|
33
30
|
* @example
|
|
34
|
-
* {{!-- results in: 5 --}}
|
|
35
31
|
* {{divide 10 2}}
|
|
36
32
|
* @param {number|string} val1 The first number.
|
|
37
33
|
* @param {number|string} val2 The second number.
|
|
@@ -41,7 +37,6 @@ export declare const divide: (val1: number | string, val2: number | string) => n
|
|
|
41
37
|
/**
|
|
42
38
|
* Round up the value.
|
|
43
39
|
* @example
|
|
44
|
-
* {{!-- results in: 6 --}}
|
|
45
40
|
* {{ceil 5.6}}
|
|
46
41
|
* @param {number|string} val Number to be rounded to nearest greater integer.
|
|
47
42
|
* @return {number}
|
|
@@ -50,7 +45,6 @@ export declare const ceil: (val: number | string) => number;
|
|
|
50
45
|
/**
|
|
51
46
|
* Rounds down a number.
|
|
52
47
|
* @example
|
|
53
|
-
* {{!-- results in: 5 --}}
|
|
54
48
|
* {{floor 5.6}}
|
|
55
49
|
* @param {number|string} val Number to be rounded to nearest lower integer.
|
|
56
50
|
* @return {number}
|
|
@@ -59,7 +53,6 @@ export declare const floor: (val: number | string) => number;
|
|
|
59
53
|
/**
|
|
60
54
|
* Returns an absolute value.
|
|
61
55
|
* @example
|
|
62
|
-
* {{!-- results in: 5.6 --}}
|
|
63
56
|
* {{abs -5.6}}
|
|
64
57
|
* @param {number} val Number to perform absolute value operation on.
|
|
65
58
|
* @return {number}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stringify an object using JSON.stringify.
|
|
3
3
|
* @example
|
|
4
|
-
* {{jsonStringify
|
|
4
|
+
* {{jsonStringify val}}
|
|
5
5
|
* @param {any} value The value to convert to a JSON string.
|
|
6
6
|
* @param {number} indent The number of space characters to use as whitespace.
|
|
7
7
|
* @return {string} A JSON string representing the given value, or undefined.
|
|
@@ -10,7 +10,7 @@ export declare const jsonStringify: (value: any, indent?: number | string) => st
|
|
|
10
10
|
/**
|
|
11
11
|
* Parses the given string using JSON.parse.
|
|
12
12
|
* @example
|
|
13
|
-
* {{jsonParse
|
|
13
|
+
* {{jsonParse val}}
|
|
14
14
|
* @param {any} value Object to stringify.
|
|
15
15
|
* @return {any} JavaScript value or object described by a string.
|
|
16
16
|
*/
|
|
@@ -11,13 +11,8 @@ export declare const replace: (value: string, find: string, replace: string) =>
|
|
|
11
11
|
/**
|
|
12
12
|
* Split `string` by the given `character`.
|
|
13
13
|
* @example
|
|
14
|
-
* {{!-- results in: ['a', 'b', 'c'] --}}
|
|
15
14
|
* {{split "a,b,c" ","}}
|
|
16
|
-
*
|
|
17
|
-
* {{!-- results in: <div>a</div><div>b</div><div>c</div> --}}
|
|
18
|
-
* {{#each (split list ',')}}
|
|
19
|
-
* <div>{{this}}</div>
|
|
20
|
-
* {{/each}}
|
|
15
|
+
* {{#each (split list ',')}}<div>{{this}}</div>{{/each}}
|
|
21
16
|
* @param {string} value String.
|
|
22
17
|
* @param {string} separator A character that delimits the substrings in this string. Default is a comma.
|
|
23
18
|
* @return {string[]} An Array of strings, split at each point where the separator occurs in the given string. The default is a comma.
|
|
@@ -56,7 +56,6 @@ export default interface AuthenticationConfig {
|
|
|
56
56
|
success_redirect: string;
|
|
57
57
|
/**
|
|
58
58
|
* URL to redirect after log off, defaults to `/login`.
|
|
59
|
-
*
|
|
60
59
|
* @example
|
|
61
60
|
* // Set the URL to redirect to in case of login failure as a string.
|
|
62
61
|
* failure_redirect: '/login',
|
|
@@ -74,9 +73,7 @@ export default interface AuthenticationConfig {
|
|
|
74
73
|
* This hook is called when authenticating a user.
|
|
75
74
|
* Please find the user information that owns the credentials based on the user name and password you received and return it.
|
|
76
75
|
* If the user who owns the credentials cannot be found, return null.
|
|
77
|
-
*
|
|
78
76
|
* Note that the user information must include an ID value that can identify the user.
|
|
79
|
-
*
|
|
80
77
|
* @example
|
|
81
78
|
* authenticate_user: async (username, password, req) => {
|
|
82
79
|
* const UserModel = require('../models/UserModel');
|
|
@@ -98,7 +95,6 @@ export default interface AuthenticationConfig {
|
|
|
98
95
|
* This hook is called when user authentication is successful.
|
|
99
96
|
* Please search and return the authenticated user information to be set in the session based on the user ID of the parameter.
|
|
100
97
|
* The returned data will be set in the req.user property and the view's session variable.
|
|
101
|
-
*
|
|
102
98
|
* @example
|
|
103
99
|
* subscribe_user: async (id) => {
|
|
104
100
|
* const UserModel = require('../models/UserModel');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* EXPRESS SWEET basic configuration interface.
|
|
4
4
|
*/
|
|
5
5
|
export default interface BasicConfig {
|
|
6
6
|
/**
|
|
@@ -32,7 +32,6 @@ export default interface BasicConfig {
|
|
|
32
32
|
* This is a hook that rewrites the base URL.
|
|
33
33
|
* 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.
|
|
34
34
|
* The default value is the referrer's origin (eg https://example.com).
|
|
35
|
-
*
|
|
36
35
|
* @example
|
|
37
36
|
* rewrite_base_url: baseUrl => {
|
|
38
37
|
* return `${baseUrl}/admin`;
|
|
@@ -45,7 +44,6 @@ export default interface BasicConfig {
|
|
|
45
44
|
* How to determine if it is an ajax request.
|
|
46
45
|
* The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
|
|
47
46
|
* 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)".
|
|
48
|
-
*
|
|
49
47
|
* @type {(req: express.Request) => boolean}
|
|
50
48
|
* @example
|
|
51
49
|
* is_ajax: req => {
|
|
@@ -58,7 +56,6 @@ export default interface BasicConfig {
|
|
|
58
56
|
/**
|
|
59
57
|
* Hooks the default behavior on request errors.
|
|
60
58
|
* If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
|
|
61
|
-
*
|
|
62
59
|
* @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
|
|
63
60
|
* @example
|
|
64
61
|
* hook_handle_error: (err, req, res, next) => {
|
|
@@ -31,7 +31,6 @@ export default interface SesOptions {
|
|
|
31
31
|
/**
|
|
32
32
|
* Hook function just before the view is rendered.
|
|
33
33
|
* For example, you can set your own local variables that can be used within the view.
|
|
34
|
-
*
|
|
35
34
|
* @example
|
|
36
35
|
* // The message set here can be referenced in the view as {{message}}.
|
|
37
36
|
* beforeRender: (req, res) => {
|
|
@@ -8,6 +8,8 @@ export default class {
|
|
|
8
8
|
#private;
|
|
9
9
|
/**
|
|
10
10
|
* Mount on application.
|
|
11
|
+
* @param {express.Express} app Express application instance.
|
|
12
|
+
* @return {Promise<void>}
|
|
11
13
|
*/
|
|
12
|
-
static mount(app: express.Express):
|
|
14
|
+
static mount(app: express.Express): Promise<void>;
|
|
13
15
|
}
|
|
@@ -5,6 +5,8 @@ import express from 'express';
|
|
|
5
5
|
export default class {
|
|
6
6
|
/**
|
|
7
7
|
* Mount on application.
|
|
8
|
+
* @param {express.Express} app Express application instance.
|
|
9
|
+
* @return {Promise<void>}
|
|
8
10
|
*/
|
|
9
|
-
static mount(app: express.Express): void
|
|
11
|
+
static mount(app: express.Express): Promise<void>;
|
|
10
12
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Read the environment variable file in options.path and set it in "process.env".
|
|
2
|
+
* Mount environment variables. Read the environment variable file in options.path and set it in "process.env".
|
|
4
3
|
*/
|
|
5
4
|
export default class {
|
|
6
5
|
/**
|
|
7
6
|
* Mount on application.
|
|
7
|
+
* @return {Promise<void>}
|
|
8
8
|
*/
|
|
9
|
-
static mount(): void
|
|
9
|
+
static mount(): Promise<void>;
|
|
10
10
|
}
|
|
@@ -5,6 +5,8 @@ import express from 'express';
|
|
|
5
5
|
export default class {
|
|
6
6
|
/**
|
|
7
7
|
* Mount on application.
|
|
8
|
+
* @param {express.Express} app Express application instance.
|
|
9
|
+
* @return {Promise<void>}
|
|
8
10
|
*/
|
|
9
|
-
static mount(app: express.Express): void
|
|
11
|
+
static mount(app: express.Express): Promise<void>;
|
|
10
12
|
}
|
|
@@ -5,6 +5,8 @@ import express from 'express';
|
|
|
5
5
|
export default class {
|
|
6
6
|
/**
|
|
7
7
|
* Mount on application.
|
|
8
|
+
* @param {express.Express} app Express application instance.
|
|
9
|
+
* @return {Promise<void>}
|
|
8
10
|
*/
|
|
9
|
-
static mount(app: express.Express): void
|
|
11
|
+
static mount(app: express.Express): Promise<void>;
|
|
10
12
|
}
|
|
@@ -8,6 +8,8 @@ import express from 'express';
|
|
|
8
8
|
export default class {
|
|
9
9
|
/**
|
|
10
10
|
* Mount on application.
|
|
11
|
+
* @param {express.Express} app Express application instance.
|
|
12
|
+
* @return {Promise<void>}
|
|
11
13
|
*/
|
|
12
|
-
static mount(app: express.Express): void
|
|
14
|
+
static mount(app: express.Express): Promise<void>;
|
|
13
15
|
}
|
|
@@ -5,10 +5,14 @@ import express from 'express';
|
|
|
5
5
|
export default class {
|
|
6
6
|
/**
|
|
7
7
|
* Mount on application.
|
|
8
|
+
* @param {express.Express} app Express application instance.
|
|
9
|
+
* @return {Promise<void>}
|
|
8
10
|
*/
|
|
9
|
-
static mount(app: express.Express): void
|
|
11
|
+
static mount(app: express.Express): Promise<void>;
|
|
10
12
|
/**
|
|
11
13
|
* Mount middleware to be executed just before drawing the view.
|
|
14
|
+
* @param {express.Express} app Express application instance.
|
|
15
|
+
* @return {Promise<void>}
|
|
12
16
|
*/
|
|
13
|
-
static mountBeforeRender(app: express.Express): void
|
|
17
|
+
static mountBeforeRender(app: express.Express): Promise<void>;
|
|
14
18
|
}
|
package/types/mount.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
/**
|
|
3
3
|
* Mount extensions on your application.
|
|
4
|
-
* @param {express.Express} app Express application instance
|
|
4
|
+
* @param {express.Express} app Express application instance.
|
|
5
|
+
* @return {Promise<void>}
|
|
5
6
|
*/
|
|
6
|
-
declare const _default: (app: express.Express) => void
|
|
7
|
+
declare const _default: (app: express.Express) => Promise<void>;
|
|
7
8
|
export default _default;
|
|
@@ -7,6 +7,8 @@ import express from 'express';
|
|
|
7
7
|
export default class {
|
|
8
8
|
/**
|
|
9
9
|
* Mount on application.
|
|
10
|
+
* @param {express.Express} app Express application instance.
|
|
11
|
+
* @return {Promise<void>}
|
|
10
12
|
*/
|
|
11
|
-
static mount(app: express.Express): void
|
|
13
|
+
static mount(app: express.Express): Promise<void>;
|
|
12
14
|
}
|
|
@@ -19,12 +19,14 @@ export default class {
|
|
|
19
19
|
/**
|
|
20
20
|
* Redirects to the page that responds immediately after successful authentication set in "success_redirect" of "config/authentication.js".
|
|
21
21
|
* @param {express.Response} res The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
|
|
22
|
+
* @return {Promise<void>}
|
|
22
23
|
*/
|
|
23
|
-
static successRedirect(res: express.Response): void
|
|
24
|
+
static successRedirect(res: express.Response): Promise<void>;
|
|
24
25
|
/**
|
|
25
26
|
* Redirects to the page that responds immediately after authentication failure set in "failure_redirect" of "config/authentication.js".
|
|
26
27
|
* @param {express.Request} req The req object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on.
|
|
27
28
|
* @param {express.Response} res The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
|
|
29
|
+
* @return {Promise<void>}
|
|
28
30
|
*/
|
|
29
|
-
static failureRedirect(req: express.Request, res: express.Response): void
|
|
31
|
+
static failureRedirect(req: express.Request, res: express.Response): Promise<void>;
|
|
30
32
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import AuthenticationConfig from '~/interfaces/AuthenticationConfig';
|
|
2
2
|
/**
|
|
3
3
|
* Get Authentication configuration (config/authentication).
|
|
4
|
-
* @return {AuthenticationConfig} Loaded configuration.
|
|
4
|
+
* @return {Promise<AuthenticationConfig>} Loaded configuration.
|
|
5
5
|
*/
|
|
6
|
-
declare const _default: () => AuthenticationConfig
|
|
6
|
+
declare const _default: () => Promise<AuthenticationConfig>;
|
|
7
7
|
export default _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BasicConfig from '~/interfaces/BasicConfig';
|
|
2
2
|
/**
|
|
3
3
|
* Get basic configuration (config/config).
|
|
4
|
-
* @return {BasicConfig} Loaded configuration.
|
|
4
|
+
* @return {Promise<BasicConfig>} Loaded configuration.
|
|
5
5
|
*/
|
|
6
|
-
declare const _default: () => BasicConfig
|
|
6
|
+
declare const _default: () => Promise<BasicConfig>;
|
|
7
7
|
export default _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import sequelize from 'sequelize';
|
|
2
2
|
/**
|
|
3
3
|
* Get database configuration (config/database).
|
|
4
|
-
* @return {sequelize.Options} Loaded configuration.
|
|
4
|
+
* @return {Promise<sequelize.Options>} Loaded configuration.
|
|
5
5
|
*/
|
|
6
|
-
declare const _default: () => sequelize.Options
|
|
6
|
+
declare const _default: () => Promise<sequelize.Options>;
|
|
7
7
|
export default _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ViewConfig from '~/interfaces/ViewConfig';
|
|
2
2
|
/**
|
|
3
3
|
* Get view configuration (config/view).
|
|
4
|
-
* @return {ViewConfig} Loaded configuration.
|
|
4
|
+
* @return {Promise<ViewConfig>} Loaded configuration.
|
|
5
5
|
*/
|
|
6
|
-
declare const _default: () => ViewConfig
|
|
6
|
+
declare const _default: () => Promise<ViewConfig>;
|
|
7
7
|
export default _default;
|
package/INSTALL-Redis.md
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
# Install Redis
|
|
2
|
-
==============
|
|
3
|
-
|
|
4
|
-
## Environment for this procedure
|
|
5
|
-
* OS: `Amazon Linux 2`
|
|
6
|
-
* Redis: `v6.2.6 or later`
|
|
7
|
-
* see more: https://redis.io/download#installation
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## Install Redis
|
|
11
|
-
1. Check the version of Redis that can be installed.
|
|
12
|
-
```sh
|
|
13
|
-
amazon-linux-extras list|grep redis
|
|
14
|
-
# Below is an example of the output.
|
|
15
|
-
# 56 redis6 available [ =stable ]
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
1. Install Redis by specifying the version.
|
|
19
|
-
```sh
|
|
20
|
-
sudo amazon-linux-extras install -y redis6
|
|
21
|
-
```
|
|
22
|
-
1. Configure and start Redis autostart.
|
|
23
|
-
```sh
|
|
24
|
-
sudo systemctl status redis.service
|
|
25
|
-
sudo systemctl start redis.service
|
|
26
|
-
sudo systemctl enable redis.service
|
|
27
|
-
sudo systemctl is-enabled redis.service
|
|
28
|
-
```
|
|
29
|
-
1. Check Redis process.
|
|
30
|
-
```sh
|
|
31
|
-
ps -ef | grep redis | grep -v grep
|
|
32
|
-
# Below is an example of the output.
|
|
33
|
-
# redis 5407 1 0 11:02 ? 00:00:00 /usr/bin/redis-server 127.0.0.1:6379
|
|
34
|
-
```
|
|
35
|
-
1. Check Redis behavior. If "redis-cli ping" returns PONG, it is success.
|
|
36
|
-
```sh
|
|
37
|
-
redis-cli ping
|
|
38
|
-
# Below is an example of the output.
|
|
39
|
-
# PONG
|
|
40
|
-
```
|
|
41
|
-
1. Test Redis read/write.
|
|
42
|
-
```sh
|
|
43
|
-
redis-cli
|
|
44
|
-
|
|
45
|
-
set myMessage "hello world"
|
|
46
|
-
# OK
|
|
47
|
-
|
|
48
|
-
get myMessage
|
|
49
|
-
# "hello world"
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Commonly used Redis commands
|
|
53
|
-
- Start Redis CLI
|
|
54
|
-
```sh
|
|
55
|
-
redis-cli
|
|
56
|
-
```
|
|
57
|
-
- Key List
|
|
58
|
-
```sh
|
|
59
|
-
redis-cli --raw keys \*
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
or
|
|
63
|
-
```sh
|
|
64
|
-
redis-cli --scan
|
|
65
|
-
```
|
|
66
|
-
- Value List
|
|
67
|
-
```sh
|
|
68
|
-
redis-cli --raw mget $(redis-cli --scan)
|
|
69
|
-
```
|
|
70
|
-
- Key and Value List
|
|
71
|
-
```sh
|
|
72
|
-
for i in $(redis-cli keys \*); do echo $i: $(redis-cli GET $i); done
|
|
73
|
-
```
|
|
74
|
-
- Delete key
|
|
75
|
-
```sh
|
|
76
|
-
redis-cli del myMessage
|
|
77
|
-
```
|
package/QUICK_START.md
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
# Quick Start
|
|
2
|
-
|
|
3
|
-
The easiest way to get started with Express Sweet is to install express-sweet-generator and automatically create a template application.
|
|
4
|
-
The following application can be started immediately by executing the template.
|
|
5
|
-
See <a href="https://takuya-motoshima.github.io/express-sweet/v2/" target="_blank">here</a> for instructions on using express-sweet.
|
|
6
|
-
|
|
7
|
-
<p align="center">
|
|
8
|
-
<img alt="login" src="screencaps/login.jpg" width="45%">
|
|
9
|
-
<img alt="users" src="screencaps/users.jpg" width="45%">
|
|
10
|
-
</p>
|
|
11
|
-
<p align="center">
|
|
12
|
-
<img alt="user-editing" src="screencaps/user-editing.jpg" width="45%">
|
|
13
|
-
<img alt="personal" src="screencaps/personal.jpg" width="45%">
|
|
14
|
-
</p>
|
|
15
|
-
|
|
16
|
-
1. Use the application generator tool, express-sweet-generator, to quickly create an application skeleton.
|
|
17
|
-
```sh
|
|
18
|
-
npm install -g express-sweet-generator
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
1. Create an Express myapp named myapp.
|
|
22
|
-
The app is created in a folder named myapp in the working directory.
|
|
23
|
-
```sh
|
|
24
|
-
express-sweet myapp
|
|
25
|
-
# If you want to use ESM, below.
|
|
26
|
-
#express-sweet -o esm myapp
|
|
27
|
-
```
|
|
28
|
-
1. Install dependent packages.
|
|
29
|
-
```sh
|
|
30
|
-
cd myapp
|
|
31
|
-
npm install
|
|
32
|
-
```
|
|
33
|
-
1. This sample application uses a database.
|
|
34
|
-
Execute the following SQL to create the database.
|
|
35
|
-
```sql
|
|
36
|
-
CREATE DATABASE IF NOT EXISTS `express_sweet_db` DEFAULT CHARACTER SET utf8mb4;
|
|
37
|
-
|
|
38
|
-
USE `express_sweet_db`;
|
|
39
|
-
|
|
40
|
-
CREATE TABLE `user` (
|
|
41
|
-
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
42
|
-
`name` varchar(30) NOT NULL,
|
|
43
|
-
`email` varchar(255) NOT NULL,
|
|
44
|
-
`password` varchar(100) NOT NULL,
|
|
45
|
-
`icon` varchar(768) NOT NULL DEFAULT MD5(RAND()),
|
|
46
|
-
`created` datetime NOT NULL DEFAULT current_timestamp(),
|
|
47
|
-
`modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
|
48
|
-
PRIMARY KEY (`id`),
|
|
49
|
-
UNIQUE KEY `ukUserEmail` (`email`),
|
|
50
|
-
UNIQUE KEY `ukUserIcon`(`icon`)
|
|
51
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
52
|
-
|
|
53
|
-
CREATE TABLE `profile` (
|
|
54
|
-
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
55
|
-
`userId` int(10) unsigned NOT NULL,
|
|
56
|
-
`address` varchar(255) NOT NULL,
|
|
57
|
-
`tel` varchar(14) NOT NULL,
|
|
58
|
-
`created` datetime NOT NULL DEFAULT current_timestamp(),
|
|
59
|
-
`modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
|
60
|
-
PRIMARY KEY (`id`),
|
|
61
|
-
UNIQUE KEY `ukProfileUserId` (`userId`),
|
|
62
|
-
CONSTRAINT `fkProfileUser` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
|
|
63
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
64
|
-
|
|
65
|
-
CREATE TABLE `comment` (
|
|
66
|
-
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
67
|
-
`userId` int(10) unsigned NOT NULL,
|
|
68
|
-
`text` text NOT NULL,
|
|
69
|
-
`created` datetime NOT NULL DEFAULT current_timestamp(),
|
|
70
|
-
`modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
|
71
|
-
PRIMARY KEY (`id`),
|
|
72
|
-
CONSTRAINT `fkCommentUser` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
|
|
73
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
74
|
-
|
|
75
|
-
CREATE TABLE `book` (
|
|
76
|
-
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
77
|
-
`userId` int(10) unsigned NOT NULL,
|
|
78
|
-
`title` text NOT NULL,
|
|
79
|
-
`created` datetime NOT NULL DEFAULT current_timestamp(),
|
|
80
|
-
`modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
|
81
|
-
PRIMARY KEY (`id`),
|
|
82
|
-
UNIQUE KEY `ukBookTitle` (`userId`, `title`(255)),
|
|
83
|
-
CONSTRAINT `fkBookUser` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
|
|
84
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
85
|
-
|
|
86
|
-
INSERT INTO `user` (`id`, `email`, `password`, `name`, `icon`) VALUES
|
|
87
|
-
(1, 'robin@example.com', 'password', 'Robin', '/upload/1.png'),
|
|
88
|
-
(2, 'taylor@example.com', 'password', 'Taylor', '/upload/2.png');
|
|
89
|
-
|
|
90
|
-
INSERT INTO `profile` (`userId`, `address`, `tel`) VALUES
|
|
91
|
-
(1, '777 Brockton Avenue, Abington MA 2351', '202-555-0105'),
|
|
92
|
-
(2, '30 Memorial Drive, Avon MA 2322', '');
|
|
93
|
-
|
|
94
|
-
INSERT INTO `comment` (`userId`, `text`) VALUES
|
|
95
|
-
(1, 'From Robin #1'),
|
|
96
|
-
(1, 'From Robin #2'),
|
|
97
|
-
(2, 'From Taylor #1');
|
|
98
|
-
|
|
99
|
-
INSERT INTO `book` (`userId`, `title`) VALUES
|
|
100
|
-
(1, 'Beautiful'),
|
|
101
|
-
(1, 'Lose Yourself'),
|
|
102
|
-
(2, 'When Im Gone');
|
|
103
|
-
```
|
|
104
|
-
1. Build front-end JS.
|
|
105
|
-
```sh
|
|
106
|
-
cd myapp/client
|
|
107
|
-
npm install
|
|
108
|
-
npm run build
|
|
109
|
-
```
|
|
110
|
-
1. Next, you need to set how the database is connected.
|
|
111
|
-
The database connection method can be set in config/database.js, so change it according to your environment.
|
|
112
|
-
See [here](https://sequelize.org/docs/v6/other-topics/migrations/#cfg) for details.
|
|
113
|
-
```js
|
|
114
|
-
// For ESM, use "export default".
|
|
115
|
-
//export default {
|
|
116
|
-
module.exports = {
|
|
117
|
-
development: {
|
|
118
|
-
username: 'root',
|
|
119
|
-
password: 'password',
|
|
120
|
-
database: 'express_sweet_db',
|
|
121
|
-
host: 'localhost',
|
|
122
|
-
dialect: 'mariadb'
|
|
123
|
-
},
|
|
124
|
-
test: {
|
|
125
|
-
username: 'root',
|
|
126
|
-
password: 'password',
|
|
127
|
-
database: 'express_sweet_db',
|
|
128
|
-
host: 'localhost',
|
|
129
|
-
dialect: 'mariadb'
|
|
130
|
-
},
|
|
131
|
-
production: {
|
|
132
|
-
username: 'root',
|
|
133
|
-
password: 'password',
|
|
134
|
-
database: 'express_sweet_db',
|
|
135
|
-
host: 'localhost',
|
|
136
|
-
dialect: 'mariadb'
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
```
|
|
140
|
-
1. The DB to be used can be defined individually for each environment.
|
|
141
|
-
Specify the environment in the .env file.
|
|
142
|
-
```js
|
|
143
|
-
NODE_ENV=development
|
|
144
|
-
```
|
|
145
|
-
1. Launch the application.
|
|
146
|
-
```sh
|
|
147
|
-
cd myapp
|
|
148
|
-
npm start
|
|
149
|
-
```
|
package/screencaps/login.jpg
DELETED
|
Binary file
|
package/screencaps/personal.jpg
DELETED
|
Binary file
|
|
Binary file
|
package/screencaps/users.jpg
DELETED
|
Binary file
|