express-sweet-generator 2.0.1 → 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/LICENSE +1 -1
- package/README.md +168 -9
- package/package.json +2 -4
- package/screencaps/demonstration.webp +0 -0
- package/templates/cjs/app.js +2 -2
- package/templates/cjs/bin/www.ejs +1 -1
- package/templates/cjs/config/authentication.js +0 -1
- package/templates/cjs/config/config.js +1 -4
- package/templates/cjs/config/database.js +6 -6
- package/templates/cjs/config/view.js +0 -1
- package/templates/cjs/models/BookModel.js +2 -2
- package/templates/cjs/models/CommentModel.js +2 -2
- package/templates/cjs/models/ProfileModel.js +2 -2
- package/templates/cjs/models/UserModel.js +2 -2
- package/templates/cjs/package.json.ejs +2 -1
- package/templates/cjs/routes/api/users.js +4 -4
- package/templates/cjs/routes/login.js +1 -1
- package/templates/cjs/routes/users.js +2 -2
- package/templates/esm/app.js +2 -2
- package/templates/esm/bin/www.ejs +1 -1
- package/templates/esm/config/authentication.js +1 -2
- package/templates/esm/config/config.js +2 -5
- package/templates/esm/config/database.js +6 -6
- package/templates/esm/config/view.js +1 -2
- package/templates/esm/ecosystem.config.js.ejs +0 -2
- package/templates/esm/models/BookModel.js +2 -2
- package/templates/esm/models/CommentModel.js +2 -2
- package/templates/esm/models/ProfileModel.js +3 -3
- package/templates/esm/models/UserModel.js +6 -6
- package/templates/esm/package.json.ejs +5 -6
- package/templates/esm/routes/api/users.js +6 -7
- package/templates/esm/routes/login.js +1 -1
- package/templates/esm/routes/users.js +2 -2
- package/templates/esm/shared/CustomValidation.js +1 -1
- package/CHANGELOG.md +0 -291
- package/QUICK_START.md +0 -158
- 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
- package/templates/cjs/exceptions/UserIconIsNotWriteable.js +0 -6
- package/templates/cjs/routes/test.js +0 -8
- package/templates/esm/exceptions/UserIconIsNotWriteable.js +0 -6
- package/templates/esm/routes/test.js +0 -8
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
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,175 @@
|
|
|
1
|
-
#
|
|
2
|
-
[
|
|
1
|
+
# EXPRESS SWEET
|
|
2
|
+
[EXPRESS SWEET](https://www.npmjs.com/package/express-sweet)'s application generator.
|
|
3
3
|
|
|
4
|
-
##
|
|
5
|
-
|
|
4
|
+
## Installation
|
|
5
|
+
```sh
|
|
6
|
+
npm install -g express-sweet-generator
|
|
7
|
+
```
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
## Quick Start
|
|
10
|
+
Use the application generator tool, `express-sweet-generator`, to quickly create an application skeleton.
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
All changes can be found [here](CHANGELOG.md).
|
|
12
|
+

|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
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.
|
|
15
|
+
```sh
|
|
16
|
+
express-sweet -o esm myapp
|
|
17
|
+
```
|
|
18
|
+
1. Then install dependencies.
|
|
19
|
+
```sh
|
|
20
|
+
cd myapp/
|
|
21
|
+
npm install
|
|
22
|
+
```
|
|
23
|
+
1. The skeleton uses a DB. Please create a DB with the following SQL.
|
|
24
|
+
```sql
|
|
25
|
+
CREATE DATABASE IF NOT EXISTS `sample_db` DEFAULT CHARACTER SET utf8mb4;
|
|
26
|
+
|
|
27
|
+
USE `sample_db`;
|
|
28
|
+
|
|
29
|
+
CREATE TABLE `user` (
|
|
30
|
+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
31
|
+
`name` varchar(30) NOT NULL,
|
|
32
|
+
`email` varchar(255) NOT NULL,
|
|
33
|
+
`password` varchar(100) NOT NULL,
|
|
34
|
+
`icon` varchar(768) NOT NULL DEFAULT MD5(RAND()),
|
|
35
|
+
`created` datetime NOT NULL DEFAULT current_timestamp(),
|
|
36
|
+
`modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
|
37
|
+
PRIMARY KEY (`id`),
|
|
38
|
+
UNIQUE KEY `ukUserEmail` (`email`),
|
|
39
|
+
UNIQUE KEY `ukUserIcon`(`icon`)
|
|
40
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
41
|
+
|
|
42
|
+
CREATE TABLE `profile` (
|
|
43
|
+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
44
|
+
`userId` int(10) unsigned NOT NULL,
|
|
45
|
+
`address` varchar(255) NOT NULL,
|
|
46
|
+
`tel` varchar(14) NOT NULL,
|
|
47
|
+
`created` datetime NOT NULL DEFAULT current_timestamp(),
|
|
48
|
+
`modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
|
49
|
+
PRIMARY KEY (`id`),
|
|
50
|
+
UNIQUE KEY `ukProfileUserId` (`userId`),
|
|
51
|
+
CONSTRAINT `fkProfileUser` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
|
|
52
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
53
|
+
|
|
54
|
+
CREATE TABLE `comment` (
|
|
55
|
+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
56
|
+
`userId` int(10) unsigned NOT NULL,
|
|
57
|
+
`text` text 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
|
+
CONSTRAINT `fkCommentUser` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
|
|
62
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
63
|
+
|
|
64
|
+
CREATE TABLE `book` (
|
|
65
|
+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
66
|
+
`userId` int(10) unsigned NOT NULL,
|
|
67
|
+
`title` text NOT NULL,
|
|
68
|
+
`created` datetime NOT NULL DEFAULT current_timestamp(),
|
|
69
|
+
`modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
|
70
|
+
PRIMARY KEY (`id`),
|
|
71
|
+
UNIQUE KEY `ukBookTitle` (`userId`, `title`(255)),
|
|
72
|
+
CONSTRAINT `fkBookUser` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
|
|
73
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
74
|
+
|
|
75
|
+
INSERT INTO `user` (`id`, `email`, `password`, `name`, `icon`) VALUES
|
|
76
|
+
(1, 'robin@example.com', 'password', 'Robin', '/upload/1.png'),
|
|
77
|
+
(2, 'taylor@example.com', 'password', 'Taylor', '/upload/2.png');
|
|
78
|
+
INSERT INTO `profile` (`userId`, `address`, `tel`) VALUES
|
|
79
|
+
(1, '777 Brockton Avenue, Abington MA 2351', '202-555-0105'),
|
|
80
|
+
(2, '30 Memorial Drive, Avon MA 2322', '');
|
|
81
|
+
INSERT INTO `comment` (`userId`, `text`) VALUES
|
|
82
|
+
(1, 'From Robin #1'),
|
|
83
|
+
(1, 'From Robin #2'),
|
|
84
|
+
(2, 'From Taylor #1');
|
|
85
|
+
INSERT INTO `book` (`userId`, `title`) VALUES
|
|
86
|
+
(1, 'Beautiful'),
|
|
87
|
+
(1, 'Lose Yourself'),
|
|
88
|
+
(2, 'When Im Gone');
|
|
89
|
+
```
|
|
90
|
+
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).
|
|
91
|
+
```js
|
|
92
|
+
export default {
|
|
93
|
+
development: {
|
|
94
|
+
username: 'root',
|
|
95
|
+
password: 'password',
|
|
96
|
+
database: 'sample_db',
|
|
97
|
+
host: 'localhost',
|
|
98
|
+
dialect: 'mariadb'
|
|
99
|
+
},
|
|
100
|
+
test: {
|
|
101
|
+
username: 'root',
|
|
102
|
+
password: 'password',
|
|
103
|
+
database: 'sample_db',
|
|
104
|
+
host: 'localhost',
|
|
105
|
+
dialect: 'mariadb'
|
|
106
|
+
},
|
|
107
|
+
production: {
|
|
108
|
+
username: 'root',
|
|
109
|
+
password: 'password',
|
|
110
|
+
database: 'sample_db',
|
|
111
|
+
host: 'localhost',
|
|
112
|
+
dialect: 'mariadb'
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
1. The DB to be accessed can be defined for each environment. Specify the environment in the `.env` file
|
|
117
|
+
```sh
|
|
118
|
+
NODE_ENV=development
|
|
119
|
+
```
|
|
120
|
+
1. Run the application with the following command.
|
|
121
|
+
```sh
|
|
122
|
+
npm start
|
|
123
|
+
```
|
|
124
|
+
1. Then, load `http://localhost:3000/` in your browser to access the app.
|
|
125
|
+
The generated app has the following directory structure:
|
|
126
|
+
```sh
|
|
127
|
+
.
|
|
128
|
+
├── .env
|
|
129
|
+
├── app.js
|
|
130
|
+
├── ecosystem.config.js
|
|
131
|
+
├── nginx.sample.conf
|
|
132
|
+
├── package.json
|
|
133
|
+
├── bin
|
|
134
|
+
│ └── www
|
|
135
|
+
├── client
|
|
136
|
+
│ ├── package.json
|
|
137
|
+
│ ├── webpack.config.js
|
|
138
|
+
│ └── src
|
|
139
|
+
├── config
|
|
140
|
+
│ ├── authentication.js
|
|
141
|
+
│ ├── config.js
|
|
142
|
+
│ ├── database.js
|
|
143
|
+
│ └── view.js
|
|
144
|
+
├── exceptions
|
|
145
|
+
│ └── UserNotFound.js
|
|
146
|
+
├── models
|
|
147
|
+
│ ├── BookModel.js
|
|
148
|
+
│ ├── CommentModel.js
|
|
149
|
+
│ ├── ProfileModel.js
|
|
150
|
+
│ └── UserModel.js
|
|
151
|
+
├── public
|
|
152
|
+
│ ├── build
|
|
153
|
+
│ └── upload
|
|
154
|
+
├── routes
|
|
155
|
+
│ ├── login.js
|
|
156
|
+
│ ├── users.js
|
|
157
|
+
│ └── api
|
|
158
|
+
│ └── users.js
|
|
159
|
+
├── shared
|
|
160
|
+
│ ├── CustomValidation.js
|
|
161
|
+
│ └── empty.js
|
|
162
|
+
└── views
|
|
163
|
+
├── edit-personal.hbs
|
|
164
|
+
├── error.hbs
|
|
165
|
+
├── login.hbs
|
|
166
|
+
├── personal.hbs
|
|
167
|
+
├── users.hbs
|
|
168
|
+
├── layout
|
|
169
|
+
│ └── default.hbs
|
|
170
|
+
└── partials
|
|
171
|
+
└── .gitkeep
|
|
172
|
+
```
|
|
14
173
|
|
|
15
174
|
## Author
|
|
16
175
|
**Takuya Motoshima**
|
package/package.json
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-sweet-generator",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.3",
|
|
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
|
-
"CHANGELOG.md",
|
|
11
9
|
"bin/",
|
|
12
10
|
"templates/",
|
|
13
11
|
"screencaps/"
|
|
Binary file
|
package/templates/cjs/app.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const express = require('express');
|
|
2
|
-
const
|
|
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
|
-
|
|
8
|
+
expressExtension.mount(app);
|
|
9
9
|
|
|
10
10
|
module.exports = app;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
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) => {
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
module.exports = {
|
|
5
5
|
development: {
|
|
6
6
|
username: 'root',
|
|
7
|
-
|
|
8
|
-
database: '
|
|
7
|
+
password: 'password',
|
|
8
|
+
database: 'sample_db',
|
|
9
9
|
host: 'localhost',
|
|
10
10
|
port: undefined,
|
|
11
11
|
dialect: 'mariadb',
|
|
@@ -14,8 +14,8 @@ module.exports = {
|
|
|
14
14
|
},
|
|
15
15
|
test: {
|
|
16
16
|
username: 'root',
|
|
17
|
-
|
|
18
|
-
database: '
|
|
17
|
+
password: 'password',
|
|
18
|
+
database: 'sample_db',
|
|
19
19
|
host: 'localhost',
|
|
20
20
|
port: undefined,
|
|
21
21
|
dialect: 'mariadb',
|
|
@@ -24,8 +24,8 @@ module.exports = {
|
|
|
24
24
|
},
|
|
25
25
|
production: {
|
|
26
26
|
username: 'root',
|
|
27
|
-
|
|
28
|
-
database: '
|
|
27
|
+
password: 'password',
|
|
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,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
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const express = require('express');
|
|
2
|
-
const
|
|
2
|
+
const expressExtension = require('express-sweet');
|
|
3
3
|
const {query, body, validationResult} = require('express-validator');
|
|
4
|
-
const router = express.Router();
|
|
5
4
|
const UserModel = require('../../models/UserModel');
|
|
6
5
|
const UserNotFound = require('../../exceptions/UserNotFound');
|
|
7
6
|
const CustomValidation = require('../../shared/CustomValidation');
|
|
8
7
|
|
|
8
|
+
const router = express.Router();
|
|
9
9
|
router.post('/login', [
|
|
10
10
|
body('email').trim().not().isEmpty().isEmail(),
|
|
11
11
|
body('password').trim().not().isEmpty()
|
|
@@ -13,12 +13,12 @@ router.post('/login', [
|
|
|
13
13
|
const errs = validationResult(req);
|
|
14
14
|
if (!errs.isEmpty())
|
|
15
15
|
return void res.status(400).json({errors: errs.array()});
|
|
16
|
-
const isAuthenticated = await Authentication.authenticate(req, res, next);
|
|
16
|
+
const isAuthenticated = await expressExtension.services.Authentication.authenticate(req, res, next);
|
|
17
17
|
res.json(isAuthenticated);
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
router.get('/logout', (req, res) => {
|
|
21
|
-
Authentication.logout(req);
|
|
21
|
+
expressExtension.services.Authentication.logout(req);
|
|
22
22
|
res.redirect('/');
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const express = require('express');
|
|
2
|
-
const router = express.Router();
|
|
3
2
|
const UserModel = require('../models/UserModel');
|
|
4
3
|
|
|
5
|
-
router
|
|
4
|
+
const router = express.Router();
|
|
5
|
+
router.get('/', (req, res) => {
|
|
6
6
|
res.render('users');
|
|
7
7
|
});
|
|
8
8
|
|
package/templates/esm/app.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import express from 'express'
|
|
2
|
-
import * as
|
|
2
|
+
import * as expressExtension from '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
|
-
|
|
8
|
+
expressExtension.mount(app);
|
|
9
9
|
|
|
10
10
|
export default app;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import UserModel from '../models/UserModel';
|
|
1
|
+
import UserModel from '../models/UserModel.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* User authentication configuration interface.
|
|
@@ -66,7 +66,6 @@ export default {
|
|
|
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
|
-
import path from 'path';
|
|
1
|
+
import path from 'node:path';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* EXPRESS SWEET basic configuration interface.
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
/**
|
|
@@ -38,7 +38,6 @@ export default {
|
|
|
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 @@ export default {
|
|
|
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 @@ export default {
|
|
|
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) => {
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
export default {
|
|
5
5
|
development: {
|
|
6
6
|
username: 'root',
|
|
7
|
-
|
|
8
|
-
database: '
|
|
7
|
+
password: 'password',
|
|
8
|
+
database: 'sample_db',
|
|
9
9
|
host: 'localhost',
|
|
10
10
|
port: undefined,
|
|
11
11
|
dialect: 'mariadb',
|
|
@@ -14,8 +14,8 @@ export default {
|
|
|
14
14
|
},
|
|
15
15
|
test: {
|
|
16
16
|
username: 'root',
|
|
17
|
-
|
|
18
|
-
database: '
|
|
17
|
+
password: 'password',
|
|
18
|
+
database: 'sample_db',
|
|
19
19
|
host: 'localhost',
|
|
20
20
|
port: undefined,
|
|
21
21
|
dialect: 'mariadb',
|
|
@@ -24,8 +24,8 @@ export default {
|
|
|
24
24
|
},
|
|
25
25
|
production: {
|
|
26
26
|
username: 'root',
|
|
27
|
-
|
|
28
|
-
database: '
|
|
27
|
+
password: 'password',
|
|
28
|
+
database: 'sample_db',
|
|
29
29
|
host: 'localhost',
|
|
30
30
|
port: undefined,
|
|
31
31
|
dialect: 'mariadb',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import path from 'path';
|
|
1
|
+
import path from 'node:path';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* View's configuration interface.
|
|
@@ -37,7 +37,6 @@ export default {
|
|
|
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,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import UserModel from './UserModel';
|
|
1
|
+
import * as expressExtension from 'express-sweet';
|
|
2
|
+
import UserModel from './UserModel.js';
|
|
3
3
|
|
|
4
|
-
export default class extends
|
|
4
|
+
export default class extends expressExtension.database.Model {
|
|
5
5
|
static get table() {
|
|
6
6
|
return 'profile';
|
|
7
7
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import * as expressExtension from 'express-sweet';
|
|
1
2
|
import {Media} from 'nodejs-shared';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import BookModel from './BookModel';
|
|
3
|
+
import UserNotFound from '../exceptions/UserNotFound.js';
|
|
4
|
+
import ProfileModel from './ProfileModel.js';
|
|
5
|
+
import CommentModel from './CommentModel.js';
|
|
6
|
+
import BookModel from './BookModel.js';
|
|
7
7
|
|
|
8
|
-
export default class extends
|
|
8
|
+
export default class extends expressExtension.database.Model {
|
|
9
9
|
static get table() {
|
|
10
10
|
return 'user';
|
|
11
11
|
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "<%- name %>",
|
|
3
3
|
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"scripts": {
|
|
5
|
-
"start": "nodemon
|
|
6
|
-
"//start": "
|
|
7
|
-
"////start": "pm2 start ecosystem.config.js",
|
|
6
|
+
"start": "nodemon --ignore client/ --ignore public/ --ignore views/ bin/www",
|
|
7
|
+
"//start": "pm2 start ecosystem.config.js",
|
|
8
8
|
"//restart": "pm2 restart ecosystem.config.js",
|
|
9
9
|
"//stop": "pm2 stop ecosystem.config.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"debug": "~2.6.9",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"express-sweet": "^2.0.1",
|
|
13
|
+
"express": "^4.19.2",
|
|
14
|
+
"express-sweet": "^2.0.3",
|
|
16
15
|
"express-validator": "^6.14.2",
|
|
17
16
|
"http-errors": "~1.6.3",
|
|
18
17
|
"nodejs-shared": "^1.0.28"
|
|
@@ -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,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('/',
|
|
5
|
+
router.get('/', (req, res) => {
|
|
6
6
|
res.render('users');
|
|
7
7
|
});
|
|
8
8
|
|
package/CHANGELOG.md
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
All notable changes to this project will be documented in this file.
|
|
3
|
-
|
|
4
|
-
## [2.0.1] - 2024/4/5
|
|
5
|
-
### Changed
|
|
6
|
-
- Removed [nodejs-shared](https://www.npmjs.com/package/nodejs-shared) package dependency.
|
|
7
|
-
|
|
8
|
-
## [2.0.0] - 2024/3/24
|
|
9
|
-
### Changed
|
|
10
|
-
- Express Sweet version 2 no longer depends on the AWS SDK.
|
|
11
|
-
The `services.AWSRekognitionClient` and `services.AWSSesClient` have been migrated to the [AWS SDK Extension](https://www.npmjs.com/package/aws-sdk-extension) NPM package, so please install from there if needed.
|
|
12
|
-
|
|
13
|
-
## [1.0.20] - 2024/3/22
|
|
14
|
-
### Changed
|
|
15
|
-
- Changed the default value of the template cookie secure attribute (`cookie_secure` in the `config/config.js` file) from true to false.
|
|
16
|
-
If `cookie_secure` is enabled, the login will always fail because no session cookie is written when the demo is run on a local server (HTTP).
|
|
17
|
-
|
|
18
|
-
## [1.0.19] - 2024/3/21
|
|
19
|
-
### Fixed
|
|
20
|
-
- The client build module (public/build) of the template was out of date, so it was updated to the latest version.
|
|
21
|
-
|
|
22
|
-
## [1.0.18] - 2024/3/6
|
|
23
|
-
### Changed
|
|
24
|
-
- Updated [metronic-extension](https://www.npmjs.com/package/metronic-extension) of templates from v1.0.1 to v3.0.9.
|
|
25
|
-
|
|
26
|
-
## [1.0.17] - 2024/3/6
|
|
27
|
-
### Fixed
|
|
28
|
-
- Fixed a typo in the name of the common JS module loaded from the template view.
|
|
29
|
-
|
|
30
|
-
## [1.0.16] - 2024/3/5
|
|
31
|
-
### Changed
|
|
32
|
-
- Changed sample DB name from `sampledb` to `express_sweet_db`.
|
|
33
|
-
|
|
34
|
-
## [1.0.15] - 2024/2/29
|
|
35
|
-
### Changed
|
|
36
|
-
- Added the ability to change color themes in template applications.
|
|
37
|
-
- Updated template application theme to Metronic v8.1.8.
|
|
38
|
-
|
|
39
|
-
## [1.0.14] - 2023/12/30
|
|
40
|
-
### Changed
|
|
41
|
-
- The `Secure` and `HttpOnly` attributes of the session cookie can now be set from the authentication configuration file (`config/authentication.js`).
|
|
42
|
-
|
|
43
|
-
config/authentication.js:
|
|
44
|
-
```js
|
|
45
|
-
/**
|
|
46
|
-
* Specifies the boolean value for the Secure Set-Cookie attribute.
|
|
47
|
-
* The default is true, which sets the Secure attribute on the cookie.
|
|
48
|
-
* @type {boolean|undefined}
|
|
49
|
-
*/
|
|
50
|
-
cookie_secure: false,
|
|
51
|
-
// cookie_secure: true,
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Specifies the boolean value for the HttpOnly Set-Cookie attribute.
|
|
55
|
-
* Defaults to true, which sets the HttpOnly attribute on the cookie.
|
|
56
|
-
* @type {boolean|undefined}
|
|
57
|
-
*/
|
|
58
|
-
cookie_httpOnly: true,
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## [1.0.13] - 2023/12/30
|
|
62
|
-
### Changed
|
|
63
|
-
- The cookie name for storing session IDs can now be set in the `cookie_name` field of the authentication configuration file (`config/authentication.js`).
|
|
64
|
-
|
|
65
|
-
config/authentication.js:
|
|
66
|
-
```js
|
|
67
|
-
/**
|
|
68
|
-
* The name of the session ID cookie to set in the response (and read from in the request).
|
|
69
|
-
* The default value is 'connect.sid'.
|
|
70
|
-
* @type {string|undefined}
|
|
71
|
-
*/
|
|
72
|
-
cookie_name: 'connect.sid'
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## [1.0.12] - 2023/7/17
|
|
76
|
-
### Changed
|
|
77
|
-
- The beforeRender option in the view configuration (config/view.js) can now specify asynchronous functions.
|
|
78
|
-
|
|
79
|
-
### Added
|
|
80
|
-
- New Math-related view helpers have been added.
|
|
81
|
-
|Helper|Description|
|
|
82
|
-
|--|--|
|
|
83
|
-
|add|Calculates the sum of two numbers.|
|
|
84
|
-
|sub|Calculates the difference of the given values.|
|
|
85
|
-
|multiply|Calculate the multiplication of the given values.|
|
|
86
|
-
|divide|Compute the division of the given values.|
|
|
87
|
-
|ceil|Round up the value.|
|
|
88
|
-
|floor|Rounds down a number.|
|
|
89
|
-
|abs|Returns an absolute value.|
|
|
90
|
-
|
|
91
|
-
## [1.0.11] - 2023/7/12
|
|
92
|
-
### Changed
|
|
93
|
-
- Moved the Ajax determination option (is_ajax) in the authentication configuration (config/authentication.js) to the basic configuration (config/config.js).
|
|
94
|
-
|
|
95
|
-
config/config.js:
|
|
96
|
-
```js
|
|
97
|
-
is_ajax: req => {
|
|
98
|
-
// If the request URL begins with /api, it is assumed to be Ajax.
|
|
99
|
-
return /^\/api/.test(req.path);
|
|
100
|
-
// return !!req.xhr;
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
- 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.
|
|
104
|
-
|
|
105
|
-
config/config.js:
|
|
106
|
-
```js
|
|
107
|
-
hook_handle_error: (err, req, res, next) => {
|
|
108
|
-
if (err.status === 404)
|
|
109
|
-
// If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
|
|
110
|
-
res.render('error-404');
|
|
111
|
-
else
|
|
112
|
-
// For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
|
|
113
|
-
res.render('error-unknown');
|
|
114
|
-
}
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## [1.0.10] - 2023/7/11
|
|
118
|
-
### Changed
|
|
119
|
-
- The URL to redirect to when login fails (failure_redirect) option in the authentication configuration (config/authentication.js) can now be defined with a function.
|
|
120
|
-
|
|
121
|
-
config/authentication.js:
|
|
122
|
-
```js
|
|
123
|
-
// Set the URL to redirect to in case of login failure as a string.
|
|
124
|
-
failure_redirect: '/login',
|
|
125
|
-
|
|
126
|
-
// Dynamically set the url to redirect to on login failure.
|
|
127
|
-
failure_redirect: (req, res) => {
|
|
128
|
-
// If the role stored in the cookie is admin, redirect to the admin login screen.
|
|
129
|
-
return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
|
|
130
|
-
},
|
|
131
|
-
```
|
|
132
|
-
- The arguments of the failureRedirect method of the authentication service class (services/Authentication) have changed.
|
|
133
|
-
The argument to the Authentication.failureRedirect method used to be just express.Response, but now it requires express.Request and express.Response.
|
|
134
|
-
|
|
135
|
-
Example of login routes:
|
|
136
|
-
```js
|
|
137
|
-
import {Router} from 'express';
|
|
138
|
-
import * as sweet from 'express-sweet';
|
|
139
|
-
const router = Router();
|
|
140
|
-
const Authentication = sweet.services.Authentication;
|
|
141
|
-
|
|
142
|
-
router.post('/login', async (req, res, next) => {
|
|
143
|
-
const isAuth = await Authentication.authenticate(req, res, next);
|
|
144
|
-
if (isAuth)
|
|
145
|
-
Authentication.successRedirect(res);
|
|
146
|
-
else
|
|
147
|
-
Authentication.failureRedirect(req, res);
|
|
148
|
-
});
|
|
149
|
-
export default router;
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## [1.0.9] - 2023/6/29
|
|
153
|
-
### Changed
|
|
154
|
-
- Changed helper function names in the view (Handlebars) from SnakeCase to CamelCase.
|
|
155
|
-
|After|Before|Description|
|
|
156
|
-
|--|--|--|
|
|
157
|
-
|notEmpty|not_empty|Check that it is not empty.|
|
|
158
|
-
|formatDate|format_date|Use moment to format the date.|
|
|
159
|
-
|cacheBusting|cache_busting|Returns the Assets path containing the file update time parameter.|
|
|
160
|
-
|jsonStringify|json_stringify|Stringify an object using JSON.stringify.|
|
|
161
|
-
|jsonParse|json_parse|Parses the given string using JSON.parse.|
|
|
162
|
-
|formatBytes|format_bytes|Convert bytes to just the right units(KB, MB, GB, TB, PB, EB, ZB, YB).|
|
|
163
|
-
|
|
164
|
-
### Added
|
|
165
|
-
- Added view helper to convert numeric values to strings with language-sensitive representations.
|
|
166
|
-
```html
|
|
167
|
-
{{number2locale 123456.789}} => 123,456.789
|
|
168
|
-
|
|
169
|
-
{{!-- German uses comma as decimal separator and period for thousands. --}}
|
|
170
|
-
{{number2locale 123456.789 'de-DE'}} => 123.456,789
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## [1.0.8] - 2023/6/12
|
|
174
|
-
### Changed
|
|
175
|
-
- In the latest express-sweet v1.0.27, an express.Request object has been added to the arguments of the beforeRender function in the view configuration (config/view.js).
|
|
176
|
-
The view settings of the template have also been changed along with this update. (templates/cjs/config/view.js, templates/esm/config/view.js)
|
|
177
|
-
|
|
178
|
-
express-sweet v1.0.27 or later (current):
|
|
179
|
-
```js
|
|
180
|
-
beforeRender: (req, res) => {}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
express-sweet v1.0.26 or earlier:
|
|
184
|
-
```js
|
|
185
|
-
beforeRender: res => {}
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
## [1.0.7] - 2022/10/24
|
|
189
|
-
### Fixed
|
|
190
|
-
- Added is_ajax option to user authentication.
|
|
191
|
-
|
|
192
|
-
config/authentication.js:
|
|
193
|
-
```js
|
|
194
|
-
is_ajax: req => {
|
|
195
|
-
// If the request URL begins with /api, it is assumed to be Ajax.
|
|
196
|
-
return /^\/api/.test(req.path);
|
|
197
|
-
// return !!req.xhr;
|
|
198
|
-
}
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
## [1.0.6] - 2022/10/20
|
|
202
|
-
### Fixed
|
|
203
|
-
- A request body object has been added to the parameters of the callback function for user authentication.
|
|
204
|
-
|
|
205
|
-
config/authentication.js:
|
|
206
|
-
```js
|
|
207
|
-
authenticate_user: async (username, password, req) => {
|
|
208
|
-
const UserModel = require('../models/UserModel');
|
|
209
|
-
return UserModel.findOne({
|
|
210
|
-
where: {
|
|
211
|
-
email: username,
|
|
212
|
-
password
|
|
213
|
-
},
|
|
214
|
-
raw: true
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
```
|
|
218
|
-
- Removed dependent packages(aws-sdk,express,passport,passport-local,sequelize) already included in express-sweet from the template package.json.
|
|
219
|
-
- Template application has been updated.
|
|
220
|
-
<p align="center">
|
|
221
|
-
<img alt="login" src="screencaps/login.jpg" width="45%">
|
|
222
|
-
<img alt="users" src="screencaps/users.jpg" width="45%">
|
|
223
|
-
</p>
|
|
224
|
-
<p align="center">
|
|
225
|
-
<img alt="user-editing" src="screencaps/user-editing.jpg" width="45%">
|
|
226
|
-
<img alt="personal" src="screencaps/personal.jpg" width="45%">
|
|
227
|
-
</p>
|
|
228
|
-
|
|
229
|
-
## [1.0.5] - 2022/7/27
|
|
230
|
-
### Fixed
|
|
231
|
-
- You can now set hook functions that are called before the view is rendered.
|
|
232
|
-
Hook functions can be used, for example, to set local variables that can be used in the view.
|
|
233
|
-
|
|
234
|
-
To use, add the beforeRender hook function to "config/view.js" as follows.
|
|
235
|
-
```js
|
|
236
|
-
beforeRender: res => {
|
|
237
|
-
res.locals.extra = 'Extra';
|
|
238
|
-
}
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
## [1.0.4] - 2022/5/18
|
|
242
|
-
### Fixed
|
|
243
|
-
- Version 1.0.18 of express-sweet now supports redis as session store for authentication, so we have added the relevant options (session_store, redis_host) to the authentication configuration of the template.
|
|
244
|
-
|
|
245
|
-
## [1.0.3] - 2022/5/17
|
|
246
|
-
### Fixed
|
|
247
|
-
- Fix UX of template views.
|
|
248
|
-
|
|
249
|
-
## [1.0.2] - 2022/2/13
|
|
250
|
-
### Fixed
|
|
251
|
-
- Changed the type of 'config/authentication.js#allow_unauthenticated' from'string[]' to'(string|RegExp)[]}'.
|
|
252
|
-
|
|
253
|
-
## [1.0.1] - 2021/6/10
|
|
254
|
-
### Fixed
|
|
255
|
-
- Removed packages that don't need to be installed from the template package.json.
|
|
256
|
-
- Added ESM template.
|
|
257
|
-
|
|
258
|
-
Create an EJS template application:
|
|
259
|
-
```sh
|
|
260
|
-
express-sweet -o esm myapp;
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
Create a CJS template application:
|
|
264
|
-
```sh
|
|
265
|
-
express-sweet myapp;
|
|
266
|
-
# or
|
|
267
|
-
express-sweet -o cjs myapp;
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
[1.0.1]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.0...v1.0.1
|
|
271
|
-
[1.0.2]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.1...v1.0.2
|
|
272
|
-
[1.0.3]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.2...v1.0.3
|
|
273
|
-
[1.0.4]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.3...v1.0.4
|
|
274
|
-
[1.0.5]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.4...v1.0.5
|
|
275
|
-
[1.0.6]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.5...v1.0.6
|
|
276
|
-
[1.0.7]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.6...v1.0.7
|
|
277
|
-
[1.0.8]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.7...v1.0.8
|
|
278
|
-
[1.0.9]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.8...v1.0.9
|
|
279
|
-
[1.0.10]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.9...v1.0.10
|
|
280
|
-
[1.0.11]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.10...v1.0.11
|
|
281
|
-
[1.0.12]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.11...v1.0.12
|
|
282
|
-
[1.0.13]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.12...v1.0.13
|
|
283
|
-
[1.0.14]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.13...v1.0.14
|
|
284
|
-
[1.0.15]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.14...v1.0.15
|
|
285
|
-
[1.0.16]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.15...v1.0.16
|
|
286
|
-
[1.0.17]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.16...v1.0.17
|
|
287
|
-
[1.0.18]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.17...v1.0.18
|
|
288
|
-
[1.0.19]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.18...v1.0.19
|
|
289
|
-
[1.0.20]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.19...v1.0.20
|
|
290
|
-
[2.0.0]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.20...v2.0.0
|
|
291
|
-
[2.0.1]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v2.0.0...v2.0.1
|
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
|
package/screencaps/login.jpg
DELETED
|
Binary file
|
package/screencaps/personal.jpg
DELETED
|
Binary file
|
|
Binary file
|
package/screencaps/users.jpg
DELETED
|
Binary file
|