express-sweet-generator 2.0.2 → 2.0.4

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.
Files changed (77) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +170 -9
  3. package/package.json +2 -3
  4. package/screencaps/demonstration.webp +0 -0
  5. package/templates/cjs/app.js +2 -2
  6. package/templates/cjs/config/authentication.js +0 -1
  7. package/templates/cjs/config/config.js +1 -4
  8. package/templates/cjs/config/database.js +3 -3
  9. package/templates/cjs/config/view.js +0 -1
  10. package/templates/cjs/models/BookModel.js +2 -2
  11. package/templates/cjs/models/CommentModel.js +2 -2
  12. package/templates/cjs/models/ProfileModel.js +2 -2
  13. package/templates/cjs/models/UserModel.js +2 -2
  14. package/templates/cjs/package.json.ejs +1 -1
  15. package/templates/cjs/public/build/editPersonal.js +54 -2
  16. package/templates/cjs/public/build/login.js +54 -2
  17. package/templates/cjs/public/build/users.js +163 -4
  18. package/templates/cjs/routes/api/users.js +4 -4
  19. package/templates/cjs/routes/login.js +1 -1
  20. package/templates/cjs/routes/users.js +2 -2
  21. package/templates/client/src/api/UserApi.js +1 -1
  22. package/templates/client/src/{pages/editPersonal.js → editPersonal.js} +1 -1
  23. package/templates/client/src/{pages/login.js → login.js} +1 -1
  24. package/templates/client/src/shared/Api.js +51 -0
  25. package/templates/client/src/shared/Datatable.js +104 -0
  26. package/templates/client/src/{pages/users.js → users.js} +4 -3
  27. package/templates/client/webpack.config.js +3 -3
  28. package/templates/esm/app.js +2 -2
  29. package/templates/esm/bin/www.ejs +1 -1
  30. package/templates/esm/config/authentication.js +1 -2
  31. package/templates/esm/config/config.js +2 -5
  32. package/templates/esm/config/database.js +3 -3
  33. package/templates/esm/config/view.js +1 -2
  34. package/templates/esm/ecosystem.config.js.ejs +0 -2
  35. package/templates/esm/models/BookModel.js +2 -2
  36. package/templates/esm/models/CommentModel.js +2 -2
  37. package/templates/esm/models/ProfileModel.js +3 -3
  38. package/templates/esm/models/UserModel.js +6 -6
  39. package/templates/esm/package.json.ejs +4 -6
  40. package/templates/esm/public/build/editPersonal.js +54 -2
  41. package/templates/esm/public/build/login.js +54 -2
  42. package/templates/esm/public/build/users.js +163 -4
  43. package/templates/esm/routes/api/users.js +6 -7
  44. package/templates/esm/routes/login.js +1 -1
  45. package/templates/esm/routes/users.js +2 -2
  46. package/templates/esm/shared/CustomValidation.js +1 -1
  47. package/QUICK_START.md +0 -158
  48. package/screencaps/login.jpg +0 -0
  49. package/screencaps/personal.jpg +0 -0
  50. package/screencaps/user-editing.jpg +0 -0
  51. package/screencaps/users.jpg +0 -0
  52. package/templates/cjs/public/build/theme/js/custom/authentication/sign-in/two-steps.js +0 -140
  53. package/templates/cjs/public/build/theme/js/custom/pages/user-profile/followers.js +0 -97
  54. package/templates/cjs/public/build/theme/js/custom/utilities/modals/create-project.js +0 -0
  55. package/templates/cjs/public/build/theme/plugins/global/fonts/fonticon/fonticon.css +0 -1
  56. package/templates/cjs/public/build/theme/plugins/global/fonts/fonticon/fonticon.eot +0 -0
  57. package/templates/cjs/public/build/theme/plugins/global/fonts/fonticon/fonticon.html +0 -1253
  58. package/templates/cjs/public/build/theme/plugins/global/fonts/fonticon/fonticon.scss +0 -361
  59. package/templates/cjs/public/build/theme/plugins/global/fonts/fonticon/fonticon.svg +0 -264
  60. package/templates/cjs/public/build/theme/plugins/global/fonts/fonticon/fonticon.ttf +0 -0
  61. package/templates/cjs/public/build/theme/plugins/global/fonts/fonticon/fonticon.woff +0 -0
  62. package/templates/cjs/public/build/theme/plugins/global/fonts/fonticon/fonticon.woff2 +0 -0
  63. package/templates/esm/public/build/theme/js/custom/authentication/sign-in/two-steps.js +0 -140
  64. package/templates/esm/public/build/theme/js/custom/pages/user-profile/followers.js +0 -97
  65. package/templates/esm/public/build/theme/js/custom/utilities/modals/create-project.js +0 -0
  66. package/templates/esm/public/build/theme/plugins/global/fonts/fonticon/fonticon.css +0 -1
  67. package/templates/esm/public/build/theme/plugins/global/fonts/fonticon/fonticon.eot +0 -0
  68. package/templates/esm/public/build/theme/plugins/global/fonts/fonticon/fonticon.html +0 -1253
  69. package/templates/esm/public/build/theme/plugins/global/fonts/fonticon/fonticon.scss +0 -361
  70. package/templates/esm/public/build/theme/plugins/global/fonts/fonticon/fonticon.svg +0 -264
  71. package/templates/esm/public/build/theme/plugins/global/fonts/fonticon/fonticon.ttf +0 -0
  72. package/templates/esm/public/build/theme/plugins/global/fonts/fonticon/fonticon.woff +0 -0
  73. package/templates/esm/public/build/theme/plugins/global/fonts/fonticon/fonticon.woff2 +0 -0
  74. /package/templates/client/src/{pages/editPersonal.css → editPersonal.css} +0 -0
  75. /package/templates/client/src/{pages/login.css → login.css} +0 -0
  76. /package/templates/client/src/{pages → modals}/UserModal.js +0 -0
  77. /package/templates/client/src/{pages/users.css → users.css} +0 -0
@@ -86,10 +86,62 @@ var __webpack_exports__ = {};
86
86
 
87
87
  // EXTERNAL MODULE: ./node_modules/metronic-extension/dist/build.js
88
88
  var build = __webpack_require__(236);
89
+ ;// CONCATENATED MODULE: ./src/shared/Api.js
90
+
91
+
92
+ /**
93
+ * Base API client class.
94
+ */
95
+ /* harmony default export */ const Api = (class extends build.components.Api {
96
+ /**
97
+ * Initializes the API client.
98
+ * @param {string} path The base URL for requests.
99
+ */
100
+ constructor(path) {
101
+ super(path, null, {
102
+ headers: {
103
+ // Indicate an AJAX request to the server.
104
+ 'X-Requested-With': 'XMLHttpRequest',
105
+ },
106
+ });
107
+ }
108
+
109
+ // /**
110
+ // * Initializes the API client.
111
+ // * @param {string} path The base URL for requests.
112
+ // * @param {string} [origin] The origin for requests.
113
+ // * @param {import('axios').AxiosRequestConfig} [options] Additional options for the Axios instance.
114
+ // */
115
+ // constructor(path, origin, options) {
116
+ // super(path, origin, Object.assign({}, {
117
+ // headers: {
118
+ // // Indicate an AJAX request to the server.
119
+ // 'X-Requested-With': 'XMLHttpRequest',
120
+ // },
121
+ // }, options));
122
+ // }
123
+
124
+ /**
125
+ * Handles API errors.
126
+ * @param {number} code The HTTP status code.
127
+ * @param {Error} err The error object.
128
+ * @return {void}
129
+ */
130
+ errorHook(code, err) {
131
+ // Check if the error object and request properties exist to avoid runtime errors
132
+ if (err && err.request && err.request.responseURL) {
133
+ const {pathname} = new URL(err.request.responseURL);
134
+ if (pathname !== '/api/users/login' && code === 401) {
135
+ // Redirect to the login page if an authentication error occurs on a non-login request.
136
+ location.replace('/');
137
+ }
138
+ }
139
+ }
140
+ });
89
141
  ;// CONCATENATED MODULE: ./src/api/UserApi.js
90
142
 
91
143
 
92
- /* harmony default export */ const UserApi = (class extends build.components.Api {
144
+ /* harmony default export */ const UserApi = (class extends components.Api {
93
145
  constructor() {
94
146
  super('/api/users');
95
147
  }
@@ -122,7 +174,7 @@ var build = __webpack_require__(236);
122
174
  return this.client.put('/profile', formData);
123
175
  }
124
176
  });
125
- ;// CONCATENATED MODULE: ./src/pages/editPersonal.js
177
+ ;// CONCATENATED MODULE: ./src/editPersonal.js
126
178
 
127
179
 
128
180
 
@@ -86,10 +86,62 @@ var __webpack_exports__ = {};
86
86
 
87
87
  // EXTERNAL MODULE: ./node_modules/metronic-extension/dist/build.js
88
88
  var build = __webpack_require__(236);
89
+ ;// CONCATENATED MODULE: ./src/shared/Api.js
90
+
91
+
92
+ /**
93
+ * Base API client class.
94
+ */
95
+ /* harmony default export */ const Api = (class extends build.components.Api {
96
+ /**
97
+ * Initializes the API client.
98
+ * @param {string} path The base URL for requests.
99
+ */
100
+ constructor(path) {
101
+ super(path, null, {
102
+ headers: {
103
+ // Indicate an AJAX request to the server.
104
+ 'X-Requested-With': 'XMLHttpRequest',
105
+ },
106
+ });
107
+ }
108
+
109
+ // /**
110
+ // * Initializes the API client.
111
+ // * @param {string} path The base URL for requests.
112
+ // * @param {string} [origin] The origin for requests.
113
+ // * @param {import('axios').AxiosRequestConfig} [options] Additional options for the Axios instance.
114
+ // */
115
+ // constructor(path, origin, options) {
116
+ // super(path, origin, Object.assign({}, {
117
+ // headers: {
118
+ // // Indicate an AJAX request to the server.
119
+ // 'X-Requested-With': 'XMLHttpRequest',
120
+ // },
121
+ // }, options));
122
+ // }
123
+
124
+ /**
125
+ * Handles API errors.
126
+ * @param {number} code The HTTP status code.
127
+ * @param {Error} err The error object.
128
+ * @return {void}
129
+ */
130
+ errorHook(code, err) {
131
+ // Check if the error object and request properties exist to avoid runtime errors
132
+ if (err && err.request && err.request.responseURL) {
133
+ const {pathname} = new URL(err.request.responseURL);
134
+ if (pathname !== '/api/users/login' && code === 401) {
135
+ // Redirect to the login page if an authentication error occurs on a non-login request.
136
+ location.replace('/');
137
+ }
138
+ }
139
+ }
140
+ });
89
141
  ;// CONCATENATED MODULE: ./src/api/UserApi.js
90
142
 
91
143
 
92
- /* harmony default export */ const UserApi = (class extends build.components.Api {
144
+ /* harmony default export */ const UserApi = (class extends components.Api {
93
145
  constructor() {
94
146
  super('/api/users');
95
147
  }
@@ -122,7 +174,7 @@ var build = __webpack_require__(236);
122
174
  return this.client.put('/profile', formData);
123
175
  }
124
176
  });
125
- ;// CONCATENATED MODULE: ./src/pages/login.js
177
+ ;// CONCATENATED MODULE: ./src/login.js
126
178
 
127
179
 
128
180
 
@@ -156,10 +156,168 @@ var build = __webpack_require__(776);
156
156
  var build_default = /*#__PURE__*/__webpack_require__.n(build);
157
157
  // EXTERNAL MODULE: ./node_modules/metronic-extension/dist/build.js
158
158
  var dist_build = __webpack_require__(236);
159
+ ;// CONCATENATED MODULE: ./src/shared/Datatable.js
160
+
161
+
162
+ /**
163
+ * Custom DataTable class extending Metronic's Datatable component.
164
+ */
165
+ /* harmony default export */ const Datatable = (class extends dist_build.components.Datatable {
166
+ /**
167
+ * Initializes the DataTable with custom options.
168
+ * @param {string|HTMLTableElement|JQuery} table The table element selector, DOM element, or jQuery object.
169
+ * @param {object} options The DataTable options.
170
+ */
171
+ constructor(table, options) {
172
+ // Initialize options with default values.
173
+ options = Object.assign({
174
+ // Option to show the column visibility toggle button.
175
+ columnVisibility: false,
176
+
177
+ // Selector for columns to be visible by default.
178
+ visibleColumns: undefined,
179
+ }, options);
180
+
181
+ if (options.columnVisibility) {
182
+ // If column visibility option is enabled.
183
+ // Place the column visibility toggle button in the DOM.
184
+ options.dom = `<'row align-items-center'<'col dataTables_pager'p><'col-auto'B>><'row'<'col-12'tr>><'row'<'col-12 dataTables_pager'p>>`;
185
+
186
+ // Add the column visibility toggle button.
187
+ options.buttons = {
188
+ dom: {
189
+ button: {
190
+ className: null,
191
+ },
192
+ buttonLiner: {
193
+ tag: null,
194
+ },
195
+ },
196
+ buttons: [
197
+ {
198
+ extend: 'colvis',
199
+ columns: options.visibleColumns,
200
+ text: '<i class="ki-solid ki-gear fs-1"></i>',
201
+ // className: 'btn btn-sm btn-icon btn-color-primary btn-active-light-primary',
202
+ className: 'btn btn-icon btn-color-gray-500 btn-active-color-primary',
203
+ align: 'container',
204
+ },
205
+ ],
206
+ };
207
+
208
+ // Remove custom options as they are no longer needed.
209
+ delete options.columnVisibility;
210
+ delete options.visibleColumns;
211
+ }
212
+
213
+ /**
214
+ * Generates a unique state key for the DataTable.
215
+ * @param {object} settings DataTables settings object.
216
+ * @return {string} The generated state key.
217
+ */
218
+ const getStateKey = (settings) => {
219
+ let stateKey = settings.sTableId;
220
+ stateKey += '_';
221
+ stateKey += location.pathname;
222
+ if (settings.nTable.getAttribute('data-ref')) {
223
+ stateKey += '/_';
224
+ stateKey += settings.nTable.getAttribute('data-ref');
225
+ }
226
+ return stateKey;
227
+ };
228
+
229
+
230
+ // // Set locale to Japanese.
231
+ // options.locale = 'ja';
232
+
233
+ // Save sorting criteria.
234
+ options.stateSave = true;
235
+ options.stateSaveCallback = (settings, data) => {
236
+ // Save state with a name that doesn't conflict with other tables.
237
+ localStorage.setItem(getStateKey(settings), JSON.stringify(data));
238
+ };
239
+ options.stateLoadCallback = (settings) => {
240
+ // Return the saved state.
241
+ return JSON.parse(localStorage.getItem(getStateKey(settings)));
242
+ };
243
+ options.stateSaveParams = (settings, data) => {
244
+ // Don't save search criteria and offset.
245
+ delete data.search;
246
+ delete data.start;
247
+ };
248
+
249
+ super(table, options);
250
+ }
251
+
252
+ /**
253
+ * Handles AJAX errors.
254
+ * @param {number} code The HTTP status code of the error.
255
+ * @return {void}
256
+ */
257
+ ajaxErrorHook(code) {
258
+ if (code === 401) {
259
+ // Redirect to login page if authentication error occurs.
260
+ location.replace('/');
261
+ }
262
+ }
263
+ });
264
+
265
+ ;// CONCATENATED MODULE: ./src/shared/Api.js
266
+
267
+
268
+ /**
269
+ * Base API client class.
270
+ */
271
+ /* harmony default export */ const Api = (class extends dist_build.components.Api {
272
+ /**
273
+ * Initializes the API client.
274
+ * @param {string} path The base URL for requests.
275
+ */
276
+ constructor(path) {
277
+ super(path, null, {
278
+ headers: {
279
+ // Indicate an AJAX request to the server.
280
+ 'X-Requested-With': 'XMLHttpRequest',
281
+ },
282
+ });
283
+ }
284
+
285
+ // /**
286
+ // * Initializes the API client.
287
+ // * @param {string} path The base URL for requests.
288
+ // * @param {string} [origin] The origin for requests.
289
+ // * @param {import('axios').AxiosRequestConfig} [options] Additional options for the Axios instance.
290
+ // */
291
+ // constructor(path, origin, options) {
292
+ // super(path, origin, Object.assign({}, {
293
+ // headers: {
294
+ // // Indicate an AJAX request to the server.
295
+ // 'X-Requested-With': 'XMLHttpRequest',
296
+ // },
297
+ // }, options));
298
+ // }
299
+
300
+ /**
301
+ * Handles API errors.
302
+ * @param {number} code The HTTP status code.
303
+ * @param {Error} err The error object.
304
+ * @return {void}
305
+ */
306
+ errorHook(code, err) {
307
+ // Check if the error object and request properties exist to avoid runtime errors
308
+ if (err && err.request && err.request.responseURL) {
309
+ const {pathname} = new URL(err.request.responseURL);
310
+ if (pathname !== '/api/users/login' && code === 401) {
311
+ // Redirect to the login page if an authentication error occurs on a non-login request.
312
+ location.replace('/');
313
+ }
314
+ }
315
+ }
316
+ });
159
317
  ;// CONCATENATED MODULE: ./src/api/UserApi.js
160
318
 
161
319
 
162
- /* harmony default export */ const UserApi = (class extends dist_build.components.Api {
320
+ /* harmony default export */ const UserApi = (class extends components.Api {
163
321
  constructor() {
164
322
  super('/api/users');
165
323
  }
@@ -192,7 +350,7 @@ var dist_build = __webpack_require__(236);
192
350
  return this.client.put('/profile', formData);
193
351
  }
194
352
  });
195
- ;// CONCATENATED MODULE: ./src/pages/UserModal.js
353
+ ;// CONCATENATED MODULE: ./src/modals/UserModal.js
196
354
 
197
355
 
198
356
 
@@ -552,7 +710,8 @@ var dist_build = __webpack_require__(236);
552
710
  dist_build.components.Dialog.close();
553
711
  }
554
712
  });
555
- ;// CONCATENATED MODULE: ./src/pages/users.js
713
+ ;// CONCATENATED MODULE: ./src/users.js
714
+
556
715
 
557
716
 
558
717
 
@@ -560,7 +719,7 @@ var dist_build = __webpack_require__(236);
560
719
 
561
720
 
562
721
  function initTable() {
563
- userTable = new dist_build.components.Datatable(ref.userTable, {
722
+ userTable = new Datatable(ref.userTable, {
564
723
  ajax: {
565
724
  url: '/api/users',
566
725
  data: d => {
@@ -1,12 +1,11 @@
1
+ import * as expressExtension from 'express-sweet';
1
2
  import {Router} from 'express';
2
- import * as sweet from 'express-sweet';
3
3
  import {query, body, validationResult} from 'express-validator';
4
- import UserModel from '../../models/UserModel';
5
- import UserNotFound from '../../exceptions/UserNotFound';
6
- import * as CustomValidation from '../../shared/CustomValidation';
4
+ import UserModel from '../../models/UserModel.js';
5
+ import UserNotFound from '../../exceptions/UserNotFound.js';
6
+ import * as CustomValidation from '../../shared/CustomValidation.js';
7
7
 
8
8
  const router = Router();
9
- const Authentication = sweet.services.Authentication;
10
9
  router.post('/login', [
11
10
  body('email').trim().not().isEmpty().isEmail(),
12
11
  body('password').trim().not().isEmpty()
@@ -14,12 +13,12 @@ router.post('/login', [
14
13
  const errs = validationResult(req);
15
14
  if (!errs.isEmpty())
16
15
  return void res.status(400).json({errors: errs.array()});
17
- const isAuthenticated = await Authentication.authenticate(req, res, next);
16
+ const isAuthenticated = await expressExtension.services.Authentication.authenticate(req, res, next);
18
17
  res.json(isAuthenticated);
19
18
  });
20
19
 
21
20
  router.get('/logout', (req, res) => {
22
- Authentication.logout(req);
21
+ expressExtension.services.Authentication.logout(req);
23
22
  res.redirect('/');
24
23
  });
25
24
 
@@ -1,6 +1,6 @@
1
1
  import {Router} from 'express';
2
- const router = Router();
3
2
 
3
+ const router = Router();
4
4
  router.get('/', (req, res) => {
5
5
  res.render('login');
6
6
  });
@@ -1,8 +1,8 @@
1
1
  import {Router} from 'express';
2
- import UserModel from '../models/UserModel';
2
+ import UserModel from '../models/UserModel.js';
3
3
 
4
4
  const router = Router();
5
- router.get('/', async (req, res) => {
5
+ router.get('/', (req, res) => {
6
6
  res.render('users');
7
7
  });
8
8
 
@@ -1,4 +1,4 @@
1
- import empty from './empty';
1
+ import empty from './empty.js';
2
2
 
3
3
  /**
4
4
  * Image Data URL validation.
package/QUICK_START.md DELETED
@@ -1,158 +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
- ```
150
-
151
- ## express-sweet command options
152
- This generator can also be further configured with the following command line flags.
153
-
154
- --version output the version number
155
- -o, --output <output> add output <module> support (esm|cjs) (defaults to cjs)
156
- -p, --port <port> application listening port (default: 3000)
157
- -f, --force force on non-empty directory
158
- -h, --help output usage information
Binary file
Binary file
Binary file
Binary file