express-sweet-generator 1.0.11 → 1.0.13
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 +64 -83
- package/LICENSE +0 -0
- package/README.md +3 -3
- package/bin/express-sweet-cli.js +0 -0
- package/package.json +1 -1
- package/templates/cjs/config/authentication.js +7 -0
- package/templates/cjs/config/view.js +2 -2
- package/templates/esm/config/authentication.js +7 -0
- package/templates/esm/config/view.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,47 +1,60 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
|
|
4
|
+
## [1.0.13] - 2023/12/30
|
|
5
|
+
### Added
|
|
6
|
+
- The cookie name for storing session IDs can now be set in the `cookie_name` field of the authentication configuration file (`config/authentication.js`).
|
|
7
|
+
|
|
8
|
+
config/authentication.js:
|
|
9
|
+
```js
|
|
10
|
+
/**
|
|
11
|
+
* The name of the session ID cookie to set in the response (and read from in the request).
|
|
12
|
+
* The default value is 'connect.sid'.
|
|
13
|
+
* @type {string|undefined}
|
|
14
|
+
*/
|
|
15
|
+
cookie_name: 'connect.sid'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## [1.0.12] - 2023/7/17
|
|
19
|
+
### Changed
|
|
20
|
+
- The beforeRender option in the view configuration (config/view.js) can now specify asynchronous functions.
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- New Math-related view helpers have been added.
|
|
24
|
+
|Helper|Description|
|
|
25
|
+
|--|--|
|
|
26
|
+
|add|Calculates the sum of two numbers.|
|
|
27
|
+
|sub|Calculates the difference of the given values.|
|
|
28
|
+
|multiply|Calculate the multiplication of the given values.|
|
|
29
|
+
|divide|Compute the division of the given values.|
|
|
30
|
+
|ceil|Round up the value.|
|
|
31
|
+
|floor|Rounds down a number.|
|
|
32
|
+
|abs|Returns an absolute value.|
|
|
33
|
+
|
|
4
34
|
## [1.0.11] - 2023/7/12
|
|
5
35
|
### Changed
|
|
6
|
-
- Moved the Ajax determination option (is_ajax) in the authentication configuration (config/authentication) to the basic configuration (config/config).
|
|
36
|
+
- Moved the Ajax determination option (is_ajax) in the authentication configuration (config/authentication.js) to the basic configuration (config/config.js).
|
|
7
37
|
|
|
8
38
|
config/config.js:
|
|
9
39
|
```js
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @type {(req: express.Request) => boolean}
|
|
16
|
-
* @example
|
|
17
|
-
* is_ajax: req => {
|
|
18
|
-
* // If the request URL begins with /api, it is assumed to be Ajax.
|
|
19
|
-
* return /^\/api/.test(req.path);
|
|
20
|
-
* // return !!req.xhr;
|
|
21
|
-
* }
|
|
22
|
-
*/
|
|
23
|
-
is_ajax: req => !!req.xhr,
|
|
40
|
+
is_ajax: req => {
|
|
41
|
+
// If the request URL begins with /api, it is assumed to be Ajax.
|
|
42
|
+
return /^\/api/.test(req.path);
|
|
43
|
+
// return !!req.xhr;
|
|
44
|
+
}
|
|
24
45
|
```
|
|
25
46
|
- The error handle option (error_handler) in the basic configuration (config/config.js) has been removed and an option to hook error handles (hook_handle_error) added instead.
|
|
26
47
|
|
|
27
48
|
config/config.js:
|
|
28
49
|
```js
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* // If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
|
|
38
|
-
* res.render('error-404');
|
|
39
|
-
* else
|
|
40
|
-
* // For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
|
|
41
|
-
* res.render('error-unknown');
|
|
42
|
-
* },
|
|
43
|
-
*/
|
|
44
|
-
hook_handle_error: undefined,
|
|
50
|
+
hook_handle_error: (err, req, res, next) => {
|
|
51
|
+
if (err.status === 404)
|
|
52
|
+
// If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
|
|
53
|
+
res.render('error-404');
|
|
54
|
+
else
|
|
55
|
+
// For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
|
|
56
|
+
res.render('error-unknown');
|
|
57
|
+
}
|
|
45
58
|
```
|
|
46
59
|
|
|
47
60
|
## [1.0.10] - 2023/7/11
|
|
@@ -118,53 +131,31 @@ All notable changes to this project will be documented in this file.
|
|
|
118
131
|
## [1.0.7] - 2022/10/24
|
|
119
132
|
### Fixed
|
|
120
133
|
- Added is_ajax option to user authentication.
|
|
134
|
+
|
|
121
135
|
config/authentication.js:
|
|
122
136
|
```js
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
* @type {(req: express.Request) => boolean}
|
|
129
|
-
* @example
|
|
130
|
-
* is_ajax: req => {
|
|
131
|
-
* // If the request URL begins with /api, it is assumed to be Ajax.
|
|
132
|
-
* return /^\/api/.test(req.path);
|
|
133
|
-
* // return !!req.xhr;
|
|
134
|
-
* }
|
|
135
|
-
*/
|
|
136
|
-
is_ajax: req => !!req.xhr
|
|
137
|
+
is_ajax: req => {
|
|
138
|
+
// If the request URL begins with /api, it is assumed to be Ajax.
|
|
139
|
+
return /^\/api/.test(req.path);
|
|
140
|
+
// return !!req.xhr;
|
|
141
|
+
}
|
|
137
142
|
```
|
|
138
143
|
|
|
139
144
|
## [1.0.6] - 2022/10/20
|
|
140
145
|
### Fixed
|
|
141
146
|
- A request body object has been added to the parameters of the callback function for user authentication.
|
|
147
|
+
|
|
142
148
|
config/authentication.js:
|
|
143
149
|
```js
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
* If the user who owns the credentials cannot be found, return null.
|
|
154
|
-
*
|
|
155
|
-
* Note that the user information must include an ID value that can identify the user.
|
|
156
|
-
*
|
|
157
|
-
* @type {(username: string, password: string, req: express.Request) => Promise<{[key: string]: any}|null>}
|
|
158
|
-
*/
|
|
159
|
-
authenticate_user: async (username, password, req) => {
|
|
160
|
-
return UserModel.findOne({
|
|
161
|
-
where: {
|
|
162
|
-
email: username,
|
|
163
|
-
password
|
|
164
|
-
},
|
|
165
|
-
raw: true
|
|
166
|
-
});
|
|
167
|
-
}
|
|
150
|
+
authenticate_user: async (username, password, req) => {
|
|
151
|
+
const UserModel = require('../models/UserModel');
|
|
152
|
+
return UserModel.findOne({
|
|
153
|
+
where: {
|
|
154
|
+
email: username,
|
|
155
|
+
password
|
|
156
|
+
},
|
|
157
|
+
raw: true
|
|
158
|
+
});
|
|
168
159
|
}
|
|
169
160
|
```
|
|
170
161
|
- Removed dependent packages(aws-sdk,express,passport,passport-local,sequelize) already included in express-sweet from the template package.json.
|
|
@@ -185,20 +176,8 @@ All notable changes to this project will be documented in this file.
|
|
|
185
176
|
|
|
186
177
|
To use, add the beforeRender hook function to "config/view.js" as follows.
|
|
187
178
|
```js
|
|
188
|
-
/**
|
|
189
|
-
* Hook function just before the view is rendered.
|
|
190
|
-
* For example, you can set your own local variables that can be used within the view.
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* // The message set here can be referenced in the view as {{message}}.
|
|
194
|
-
* beforeRender: res => {
|
|
195
|
-
* res.locals.message = 'Hello World';
|
|
196
|
-
* }
|
|
197
|
-
*
|
|
198
|
-
* @type {(res: express.Response) => void}
|
|
199
|
-
*/
|
|
200
179
|
beforeRender: res => {
|
|
201
|
-
res.locals.
|
|
180
|
+
res.locals.extra = 'Extra';
|
|
202
181
|
}
|
|
203
182
|
```
|
|
204
183
|
|
|
@@ -241,4 +220,6 @@ All notable changes to this project will be documented in this file.
|
|
|
241
220
|
[1.0.8]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.7...v1.0.8
|
|
242
221
|
[1.0.9]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.8...v1.0.9
|
|
243
222
|
[1.0.10]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.9...v1.0.10
|
|
244
|
-
[1.0.11]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.10...v1.0.11
|
|
223
|
+
[1.0.11]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.10...v1.0.11
|
|
224
|
+
[1.0.12]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.11...v1.0.12
|
|
225
|
+
[1.0.13]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.12...v1.0.13
|
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
[](https://takuya-motoshima.github.io/express-sweet
|
|
1
|
+
[](https://takuya-motoshima.github.io/express-sweet/v1/install.html)
|
|
2
2
|
|
|
3
3
|
[Express Sweet](https://www.npmjs.com/package/express-sweet) application generator.
|
|
4
4
|
|
|
5
5
|
## Documentation
|
|
6
|
-
* [Express Sweet Documentation](https://takuya-motoshima.github.io/express-sweet/)
|
|
6
|
+
* [Express Sweet Documentation](https://takuya-motoshima.github.io/express-sweet/v1/)
|
|
7
7
|
* [Changelog](CHANGELOG.md)
|
|
8
8
|
|
|
9
9
|
## Quick Start
|
|
10
10
|
The easiest way to get started with Express Sweet is to install express-sweet-generator and automatically create a template application.
|
|
11
11
|
The following application can be started immediately by executing the template.
|
|
12
|
-
See <a href="https://takuya-motoshima.github.io/express-sweet/" target="_blank">here</a> for instructions on using express-sweet.
|
|
12
|
+
See <a href="https://takuya-motoshima.github.io/express-sweet/v1/" target="_blank">here</a> for instructions on using express-sweet.
|
|
13
13
|
|
|
14
14
|
<p align="center">
|
|
15
15
|
<img alt="login" src="screencaps/login.png" width="45%">
|
package/bin/express-sweet-cli.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -16,6 +16,13 @@ module.exports = {
|
|
|
16
16
|
*/
|
|
17
17
|
session_store: 'memory',
|
|
18
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
|
+
|
|
19
26
|
/**
|
|
20
27
|
* If the session is stored in "redis", this field is required and should be set to the hostname of the Redis server.
|
|
21
28
|
* For example, to connect to redis on localhost on port 6379, set "redis://localhost:6379".
|
|
@@ -41,10 +41,10 @@ module.exports = {
|
|
|
41
41
|
* @example
|
|
42
42
|
* // The message set here can be referenced in the view as {{message}}.
|
|
43
43
|
* beforeRender: (req, res) => {
|
|
44
|
-
* res.locals.
|
|
44
|
+
* res.locals.extra = 'Extra';
|
|
45
45
|
* }
|
|
46
46
|
*
|
|
47
|
-
* @type {(res: express.Response) => void}
|
|
47
|
+
* @type {(res: express.Response) => Promise<void>|void}
|
|
48
48
|
*/
|
|
49
49
|
beforeRender: (req, res) => {}
|
|
50
50
|
}
|
|
@@ -16,6 +16,13 @@ export default {
|
|
|
16
16
|
*/
|
|
17
17
|
session_store: 'memory',
|
|
18
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
|
+
|
|
19
26
|
/**
|
|
20
27
|
* If the session is stored in "redis", this field is required and should be set to the hostname of the Redis server.
|
|
21
28
|
* For example, to connect to redis on localhost on port 6379, set "redis://localhost:6379".
|
|
@@ -41,10 +41,10 @@ export default {
|
|
|
41
41
|
* @example
|
|
42
42
|
* // The message set here can be referenced in the view as {{message}}.
|
|
43
43
|
* beforeRender: (req, res) => {
|
|
44
|
-
* res.locals.
|
|
44
|
+
* res.locals.extra = 'Extra';
|
|
45
45
|
* }
|
|
46
46
|
*
|
|
47
|
-
* @type {(res: express.Response) => void}
|
|
47
|
+
* @type {(res: express.Response) => Promise<void>|void}
|
|
48
48
|
*/
|
|
49
49
|
beforeRender: (req, res) => {}
|
|
50
50
|
}
|