express-sweet-generator 1.0.12 → 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 CHANGED
@@ -1,16 +1,26 @@
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
+
4
18
  ## [1.0.12] - 2023/7/17
5
19
  ### Changed
6
20
  - The beforeRender option in the view configuration (config/view.js) can now specify asynchronous functions.
7
21
 
8
22
  ### Added
9
23
  - New Math-related view helpers have been added.
10
-
11
- See [here](https://takuya-motoshima.github.io/express-sweet/#view-math-helper) how to use the helper.
12
-
13
- Added view helpers:
14
24
  |Helper|Description|
15
25
  |--|--|
16
26
  |add|Calculates the sum of two numbers.|
@@ -27,41 +37,24 @@ All notable changes to this project will be documented in this file.
27
37
 
28
38
  config/config.js:
29
39
  ```js
30
- /**
31
- * How to determine if it is an ajax request.
32
- * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
33
- * 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)".
34
- *
35
- * @type {(req: express.Request) => boolean}
36
- * @example
37
- * is_ajax: req => {
38
- * // If the request URL begins with /api, it is assumed to be Ajax.
39
- * return /^\/api/.test(req.path);
40
- * // return !!req.xhr;
41
- * }
42
- */
43
- 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
+ }
44
45
  ```
45
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.
46
47
 
47
48
  config/config.js:
48
49
  ```js
49
- /**
50
- * Hooks the default behavior on request errors.
51
- * If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
52
- *
53
- * @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
54
- * @example
55
- * hook_handle_error: (err, req, res, next) => {
56
- * if (err.status === 404)
57
- * // If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
58
- * res.render('error-404');
59
- * else
60
- * // For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
61
- * res.render('error-unknown');
62
- * },
63
- */
64
- 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
+ }
65
58
  ```
66
59
 
67
60
  ## [1.0.10] - 2023/7/11
@@ -138,53 +131,31 @@ All notable changes to this project will be documented in this file.
138
131
  ## [1.0.7] - 2022/10/24
139
132
  ### Fixed
140
133
  - Added is_ajax option to user authentication.
134
+
141
135
  config/authentication.js:
142
136
  ```js
143
- /**
144
- * How to determine if it is an ajax request.
145
- * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
146
- * 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)".
147
- *
148
- * @type {(req: express.Request) => boolean}
149
- * @example
150
- * is_ajax: req => {
151
- * // If the request URL begins with /api, it is assumed to be Ajax.
152
- * return /^\/api/.test(req.path);
153
- * // return !!req.xhr;
154
- * }
155
- */
156
- 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
+ }
157
142
  ```
158
143
 
159
144
  ## [1.0.6] - 2022/10/20
160
145
  ### Fixed
161
146
  - A request body object has been added to the parameters of the callback function for user authentication.
147
+
162
148
  config/authentication.js:
163
149
  ```js
164
- const UserModel = require('../models/UserModel');
165
-
166
- /**
167
- * User authentication configuration interface.
168
- */
169
- module.exports = {
170
- /**
171
- * This hook is called when authenticating a user.
172
- * Please find the user information that owns the credentials based on the user name and password you received and return it.
173
- * If the user who owns the credentials cannot be found, return null.
174
- *
175
- * Note that the user information must include an ID value that can identify the user.
176
- *
177
- * @type {(username: string, password: string, req: express.Request) => Promise<{[key: string]: any}|null>}
178
- */
179
- authenticate_user: async (username, password, req) => {
180
- return UserModel.findOne({
181
- where: {
182
- email: username,
183
- password
184
- },
185
- raw: true
186
- });
187
- }
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
+ });
188
159
  }
189
160
  ```
190
161
  - Removed dependent packages(aws-sdk,express,passport,passport-local,sequelize) already included in express-sweet from the template package.json.
@@ -205,20 +176,8 @@ All notable changes to this project will be documented in this file.
205
176
 
206
177
  To use, add the beforeRender hook function to "config/view.js" as follows.
207
178
  ```js
208
- /**
209
- * Hook function just before the view is rendered.
210
- * For example, you can set your own local variables that can be used within the view.
211
- *
212
- * @example
213
- * // The message set here can be referenced in the view as {{message}}.
214
- * beforeRender: res => {
215
- * res.locals.message = 'Hello World';
216
- * }
217
- *
218
- * @type {(res: express.Response) => void}
219
- */
220
179
  beforeRender: res => {
221
- res.locals.message = 'Hello World';
180
+ res.locals.extra = 'Extra';
222
181
  }
223
182
  ```
224
183
 
@@ -262,4 +221,5 @@ All notable changes to this project will be documented in this file.
262
221
  [1.0.9]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.8...v1.0.9
263
222
  [1.0.10]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.9...v1.0.10
264
223
  [1.0.11]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.10...v1.0.11
265
- [1.0.12]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.11...v1.0.12
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
- [![Express Sweet Logo](hero.svg)](https://takuya-motoshima.github.io/express-sweet/#install)
1
+ [![Express Sweet Logo](hero.svg)](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%">
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet-generator",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Express Sweet application generator.",
5
5
  "main": "bin/express-sweet-cli.js",
6
6
  "files": [
@@ -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,7 +41,7 @@ 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.message = 'Hello World';
44
+ * res.locals.extra = 'Extra';
45
45
  * }
46
46
  *
47
47
  * @type {(res: express.Response) => Promise<void>|void}
@@ -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,7 +41,7 @@ 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.message = 'Hello World';
44
+ * res.locals.extra = 'Extra';
45
45
  * }
46
46
  *
47
47
  * @type {(res: express.Response) => Promise<void>|void}