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
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2022 Takuya Motoshima
1
+ Copyright 2024 Takuya Motoshima
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -1,16 +1,177 @@
1
- # Express Sweet
2
- [Express Sweet](https://www.npmjs.com/package/express-sweet) application generator.
1
+ # EXPRESS SWEET
2
+ [EXPRESS SWEET](https://www.npmjs.com/package/express-sweet)'s application generator.
3
3
 
4
- ## Documentation
5
- The latest API reference for Express Sweet can be found [here](https://takuya-motoshima.github.io/express-sweet/v2/).
4
+ A comprehensive list of changes in each version may be found in the [CHANGELOG](CHANGELOG.md).
6
5
 
7
- The API reference for previous versions can be found [here](https://takuya-motoshima.github.io/express-sweet/v1/).
8
-
9
- ## Release Notes
10
- All changes can be found [here](https://github.com/takuya-motoshima/express-sweet/blob/HEAD/CHANGELOG.md).
6
+ ## Installation
7
+ ```sh
8
+ npm install -g express-sweet-generator
9
+ ```
11
10
 
12
11
  ## Quick Start
13
- See [here](QUICK_START.md).
12
+ Use the application generator tool, `express-sweet-generator`, to quickly create an application skeleton.
13
+
14
+ ![Image](screencaps/demonstration.webp)
15
+
16
+ 1. For example, the following creates an Express app named `myapp`. The app will be created in a folder named `myapp` in the current working directory.
17
+ ```sh
18
+ express-sweet -o esm myapp
19
+ ```
20
+ 1. Then install dependencies.
21
+ ```sh
22
+ cd myapp/
23
+ npm install
24
+ ```
25
+ 1. The skeleton uses a DB. Please create a DB with the following SQL.
26
+ ```sql
27
+ CREATE DATABASE IF NOT EXISTS `sample_db` DEFAULT CHARACTER SET utf8mb4;
28
+
29
+ USE `sample_db`;
30
+
31
+ CREATE TABLE `user` (
32
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
33
+ `name` varchar(30) NOT NULL,
34
+ `email` varchar(255) NOT NULL,
35
+ `password` varchar(100) NOT NULL,
36
+ `icon` varchar(768) NOT NULL DEFAULT MD5(RAND()),
37
+ `created` datetime NOT NULL DEFAULT current_timestamp(),
38
+ `modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
39
+ PRIMARY KEY (`id`),
40
+ UNIQUE KEY `ukUserEmail` (`email`),
41
+ UNIQUE KEY `ukUserIcon`(`icon`)
42
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
43
+
44
+ CREATE TABLE `profile` (
45
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
46
+ `userId` int(10) unsigned NOT NULL,
47
+ `address` varchar(255) NOT NULL,
48
+ `tel` varchar(14) NOT NULL,
49
+ `created` datetime NOT NULL DEFAULT current_timestamp(),
50
+ `modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
51
+ PRIMARY KEY (`id`),
52
+ UNIQUE KEY `ukProfileUserId` (`userId`),
53
+ CONSTRAINT `fkProfileUser` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
54
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
55
+
56
+ CREATE TABLE `comment` (
57
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
58
+ `userId` int(10) unsigned NOT NULL,
59
+ `text` text NOT NULL,
60
+ `created` datetime NOT NULL DEFAULT current_timestamp(),
61
+ `modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
62
+ PRIMARY KEY (`id`),
63
+ CONSTRAINT `fkCommentUser` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
64
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
65
+
66
+ CREATE TABLE `book` (
67
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
68
+ `userId` int(10) unsigned NOT NULL,
69
+ `title` text NOT NULL,
70
+ `created` datetime NOT NULL DEFAULT current_timestamp(),
71
+ `modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
72
+ PRIMARY KEY (`id`),
73
+ UNIQUE KEY `ukBookTitle` (`userId`, `title`(255)),
74
+ CONSTRAINT `fkBookUser` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
75
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
76
+
77
+ INSERT INTO `user` (`id`, `email`, `password`, `name`, `icon`) VALUES
78
+ (1, 'robin@example.com', 'password', 'Robin', '/upload/1.png'),
79
+ (2, 'taylor@example.com', 'password', 'Taylor', '/upload/2.png');
80
+ INSERT INTO `profile` (`userId`, `address`, `tel`) VALUES
81
+ (1, '777 Brockton Avenue, Abington MA 2351', '202-555-0105'),
82
+ (2, '30 Memorial Drive, Avon MA 2322', '');
83
+ INSERT INTO `comment` (`userId`, `text`) VALUES
84
+ (1, 'From Robin #1'),
85
+ (1, 'From Robin #2'),
86
+ (2, 'From Taylor #1');
87
+ INSERT INTO `book` (`userId`, `title`) VALUES
88
+ (1, 'Beautiful'),
89
+ (1, 'Lose Yourself'),
90
+ (2, 'When Im Gone');
91
+ ```
92
+ 1. Set the DB connection method in `config/database.js`. For details, please refer to [here](https://sequelize.org/docs/v6/other-topics/migrations/#cfg).
93
+ ```js
94
+ export default {
95
+ development: {
96
+ username: 'root',
97
+ password: 'password',
98
+ database: 'sample_db',
99
+ host: 'localhost',
100
+ dialect: 'mariadb'
101
+ },
102
+ test: {
103
+ username: 'root',
104
+ password: 'password',
105
+ database: 'sample_db',
106
+ host: 'localhost',
107
+ dialect: 'mariadb'
108
+ },
109
+ production: {
110
+ username: 'root',
111
+ password: 'password',
112
+ database: 'sample_db',
113
+ host: 'localhost',
114
+ dialect: 'mariadb'
115
+ }
116
+ }
117
+ ```
118
+ 1. The DB to be accessed can be defined for each environment. Specify the environment in the `.env` file
119
+ ```sh
120
+ NODE_ENV=development
121
+ ```
122
+ 1. Run the application with the following command.
123
+ ```sh
124
+ npm start
125
+ ```
126
+ 1. Then, load `http://localhost:3000/` in your browser to access the app.
127
+ The generated app has the following directory structure:
128
+ ```sh
129
+ .
130
+ ├── .env
131
+ ├── app.js
132
+ ├── ecosystem.config.js
133
+ ├── nginx.sample.conf
134
+ ├── package.json
135
+ ├── bin
136
+ │ └── www
137
+ ├── client
138
+ │ ├── package.json
139
+ │ ├── webpack.config.js
140
+ │ └── src
141
+ ├── config
142
+ │ ├── authentication.js
143
+ │ ├── config.js
144
+ │ ├── database.js
145
+ │ └── view.js
146
+ ├── exceptions
147
+ │ └── UserNotFound.js
148
+ ├── models
149
+ │ ├── BookModel.js
150
+ │ ├── CommentModel.js
151
+ │ ├── ProfileModel.js
152
+ │ └── UserModel.js
153
+ ├── public
154
+ │ ├── build
155
+ │ └── upload
156
+ ├── routes
157
+ │ ├── login.js
158
+ │ ├── users.js
159
+ │ └── api
160
+ │ └── users.js
161
+ ├── shared
162
+ │ ├── CustomValidation.js
163
+ │ └── empty.js
164
+ └── views
165
+ ├── edit-personal.hbs
166
+ ├── error.hbs
167
+ ├── login.hbs
168
+ ├── personal.hbs
169
+ ├── users.hbs
170
+ ├── layout
171
+ │ └── default.hbs
172
+ └── partials
173
+ └── .gitkeep
174
+ ```
14
175
 
15
176
  ## Author
16
177
  **Takuya Motoshima**
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "express-sweet-generator",
3
- "version": "2.0.2",
4
- "description": "Express Sweet application generator.",
3
+ "version": "2.0.4",
4
+ "description": "EXPRESS SWEET application generator.",
5
5
  "main": "bin/express-sweet-cli.js",
6
6
  "files": [
7
7
  "LICENSE",
8
8
  "README.md",
9
- "QUICK_START.md",
10
9
  "bin/",
11
10
  "templates/",
12
11
  "screencaps/"
Binary file
@@ -1,10 +1,10 @@
1
1
  const express = require('express');
2
- const sweet = require('express-sweet');
2
+ const expressExtension = require('express-sweet');
3
3
 
4
4
  // Creates and configures an ExpressJS web server.
5
5
  const app = express();
6
6
 
7
7
  // Mount the extension.
8
- sweet.mount(app);
8
+ expressExtension.mount(app);
9
9
 
10
10
  module.exports = app;
@@ -66,7 +66,6 @@ module.exports = {
66
66
 
67
67
  /**
68
68
  * URL to redirect after log off, defaults to `/login`.
69
- *
70
69
  * @example
71
70
  * // Set the URL to redirect to in case of login failure as a string.
72
71
  * failure_redirect: '/login',
@@ -1,7 +1,7 @@
1
1
  const path = require('path');
2
2
 
3
3
  /**
4
- * Express Sweet basic configuration interface.
4
+ * EXPRESS SWEET basic configuration interface.
5
5
  */
6
6
  module.exports = {
7
7
  /**
@@ -38,7 +38,6 @@ module.exports = {
38
38
  * This is a hook that rewrites the base URL.
39
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
40
  * The default value is the referrer's origin (eg https://example.com).
41
- *
42
41
  * @example
43
42
  * rewrite_base_url: baseUrl => {
44
43
  * return `${baseUrl}/admin`;
@@ -54,7 +53,6 @@ module.exports = {
54
53
  * How to determine if it is an ajax request.
55
54
  * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
56
55
  * 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
- *
58
56
  * @type {(req: express.Request) => boolean}
59
57
  * @example
60
58
  * is_ajax: req => {
@@ -68,7 +66,6 @@ module.exports = {
68
66
  /**
69
67
  * Hooks the default behavior on request errors.
70
68
  * If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
71
- *
72
69
  * @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
73
70
  * @example
74
71
  * hook_handle_error: (err, req, res, next) => {
@@ -5,7 +5,7 @@ module.exports = {
5
5
  development: {
6
6
  username: 'root',
7
7
  password: 'password',
8
- database: 'express_sweet_db',
8
+ database: 'sample_db',
9
9
  host: 'localhost',
10
10
  port: undefined,
11
11
  dialect: 'mariadb',
@@ -15,7 +15,7 @@ module.exports = {
15
15
  test: {
16
16
  username: 'root',
17
17
  password: 'password',
18
- database: 'express_sweet_db',
18
+ database: 'sample_db',
19
19
  host: 'localhost',
20
20
  port: undefined,
21
21
  dialect: 'mariadb',
@@ -25,7 +25,7 @@ module.exports = {
25
25
  production: {
26
26
  username: 'root',
27
27
  password: 'password',
28
- database: 'express_sweet_db',
28
+ database: 'sample_db',
29
29
  host: 'localhost',
30
30
  port: undefined,
31
31
  dialect: 'mariadb',
@@ -37,7 +37,6 @@ module.exports = {
37
37
  /**
38
38
  * Hook function just before the view is rendered.
39
39
  * For example, you can set your own local variables that can be used within the view.
40
- *
41
40
  * @example
42
41
  * // The message set here can be referenced in the view as {{message}}.
43
42
  * beforeRender: (req, res) => {
@@ -1,6 +1,6 @@
1
- const Model = require('express-sweet').database.Model;
1
+ const expressExtension = require('express-sweet');
2
2
 
3
- module.exports = class extends Model {
3
+ module.exports = class extends expressExtension.database.Model {
4
4
  static get table() {
5
5
  return 'book';
6
6
  }
@@ -1,6 +1,6 @@
1
- const Model = require('express-sweet').database.Model;
1
+ const expressExtension = require('express-sweet');
2
2
 
3
- module.exports = class extends Model {
3
+ module.exports = class extends expressExtension.database.Model {
4
4
  static get table() {
5
5
  return 'comment';
6
6
  }
@@ -1,6 +1,6 @@
1
- const Model = require('express-sweet').database.Model;
1
+ const expressExtension = require('express-sweet');
2
2
 
3
- module.exports = class extends Model {
3
+ module.exports = class extends expressExtension.database.Model {
4
4
  static get table() {
5
5
  return 'profile';
6
6
  }
@@ -1,8 +1,8 @@
1
+ const expressExtension = require('express-sweet');
1
2
  const {Media} = require('nodejs-shared');
2
- const Model = require('express-sweet').database.Model;
3
3
  const UserNotFound = require('../exceptions/UserNotFound');
4
4
 
5
- module.exports = class extends Model {
5
+ module.exports = class extends expressExtension.database.Model {
6
6
  static get table() {
7
7
  return 'user';
8
8
  }
@@ -10,7 +10,7 @@
10
10
  "dependencies": {
11
11
  "debug": "~2.6.9",
12
12
  "express": "^4.19.2",
13
- "express-sweet": "^2.0.2",
13
+ "express-sweet": "^2.0.3",
14
14
  "express-validator": "^6.14.2",
15
15
  "http-errors": "~1.6.3",
16
16
  "nodejs-shared": "^1.0.28"
@@ -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