create-sip 0.10.5 → 0.10.7
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/expressapi/README.md +1 -3
- package/expressapi/app/controllers/authcontroller.js +6 -6
- package/expressapi/app/controllers/usercontroller.js +2 -2
- package/expressapi/app/database/database.js +3 -3
- package/expressapi/app/index.js +6 -5
- package/expressapi/app/middlewares/authjwt.js +6 -4
- package/expressapi/app/models/user.js +5 -4
- package/expressapi/app/routes/api.js +5 -5
- package/expressapi/package.json +2 -1
- package/expressapi/tools/genkey.js +6 -6
- package/manager.js +2 -25
- package/package.json +1 -1
- package/utils.js +30 -0
package/expressapi/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import bcrypt from 'bcryptjs'
|
|
2
|
+
import jwt from 'jsonwebtoken'
|
|
3
|
+
import User from '../models/user.js'
|
|
4
|
+
import config from '../../config/default.json' assert { type: 'json' }
|
|
5
|
+
|
|
6
6
|
const AuthController = {
|
|
7
7
|
async register(req, res) {
|
|
8
8
|
var clientError = false;
|
|
@@ -100,4 +100,4 @@ const AuthController = {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
export default AuthController
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import Sequelize from 'sequelize'
|
|
2
|
+
import config from '../../config/default.json' assert { type: 'json' }
|
|
3
3
|
|
|
4
4
|
if(config.app.log != false) {
|
|
5
5
|
var log = console.log
|
|
@@ -19,4 +19,4 @@ const sequelize = new Sequelize(
|
|
|
19
19
|
}
|
|
20
20
|
)
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
export default sequelize
|
package/expressapi/app/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import express from 'express'
|
|
2
|
+
import morgan from 'morgan'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import router from './routes/api.js'
|
|
5
|
+
import config from '../config/default.json' assert { type: 'json' }
|
|
6
|
+
|
|
3
7
|
const app = express()
|
|
4
|
-
const fs = require('fs')
|
|
5
|
-
const router = require('./routes/api')
|
|
6
|
-
const config = require('../config/default.json')
|
|
7
8
|
|
|
8
9
|
const PORT = config.app.port || 8000
|
|
9
10
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import jwt from 'jsonwebtoken';
|
|
2
|
+
import config from '../../config/default.json' assert { type: 'json' };
|
|
3
|
+
|
|
4
|
+
const verifyToken = (req, res, next) => {
|
|
5
5
|
let authData = req.headers.authorization;
|
|
6
6
|
if(!authData) {
|
|
7
7
|
return res.status(403).send({
|
|
@@ -20,3 +20,5 @@ exports.verifyToken = (req, res, next) => {
|
|
|
20
20
|
next()
|
|
21
21
|
})
|
|
22
22
|
};
|
|
23
|
+
|
|
24
|
+
export default verifyToken
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { DataTypes } from 'sequelize'
|
|
2
|
+
import sequelize from '../database/database.js'
|
|
3
|
+
|
|
4
4
|
const User = sequelize.define('User', {
|
|
5
5
|
id: {
|
|
6
6
|
type: DataTypes.INTEGER,
|
|
@@ -16,4 +16,5 @@ const User = sequelize.define('User', {
|
|
|
16
16
|
sequelize.sync({
|
|
17
17
|
force: false
|
|
18
18
|
})
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
export default User
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import Router from 'express'
|
|
2
2
|
const router = Router()
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import AuthController from '../controllers/authcontroller.js';
|
|
5
|
+
import UserController from '../controllers/usercontroller.js';
|
|
6
|
+
import verifyToken from '../middlewares/authjwt.js';
|
|
7
7
|
|
|
8
8
|
router.post('/register', AuthController.register)
|
|
9
9
|
router.post('/login', AuthController.login)
|
|
10
10
|
router.get('/users', [verifyToken], UserController.index)
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
export default router
|
package/expressapi/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
1
|
+
import fs from 'fs/promises'
|
|
2
|
+
import { generateApiKey } from 'generate-api-key'
|
|
3
|
+
|
|
4
|
+
const fileName = new URL('../config/default.json', import.meta.url).pathname
|
|
5
5
|
|
|
6
6
|
function generateKey(size = 32, format = 'base64') {
|
|
7
7
|
const buffer = crypto.randomBytes(size);
|
|
8
8
|
return buffer.toString(format);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
fs.readFile(
|
|
11
|
+
fs.readFile(fileName)
|
|
12
12
|
.then(body => JSON.parse(body))
|
|
13
13
|
.then(json => {
|
|
14
14
|
json.app.key = generateApiKey({method: 'bytes', length: 32})
|
|
15
15
|
return json
|
|
16
16
|
})
|
|
17
17
|
.then(json => JSON.stringify(json, null, 4))
|
|
18
|
-
.then(body => fs.writeFile(
|
|
18
|
+
.then(body => fs.writeFile(fileName, body, 'utf8'))
|
|
19
19
|
.catch(error => console.log(error))
|
package/manager.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { copyDir, updatePackageName } = require('./utils');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const dir = path.join(__dirname);
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
const genWebpage = (target) => {
|
|
7
6
|
copyDir(`${dir}/webpage`, target);
|
|
8
7
|
}
|
|
@@ -61,32 +60,10 @@ const genExpressApi = (target) => {
|
|
|
61
60
|
copyDir(`${dir}/expressapi`, target);
|
|
62
61
|
updatePackageName(`${target}/package.json`, target);
|
|
63
62
|
console.log('ExpressJS REST API sablon created');
|
|
63
|
+
console.log('Make a config/default.json');
|
|
64
64
|
console.log('Read docs/user_doc.md');
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const updatePackageName = (filePath, newName) => {
|
|
68
|
-
const content = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
69
|
-
if (content.name) {
|
|
70
|
-
content.name = newName;
|
|
71
|
-
fs.writeFileSync(filePath, JSON.stringify(content, null, 2));
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const copyDir = (srcDir, destDir) => {
|
|
76
|
-
fs.mkdirSync(destDir, { recursive: true });
|
|
77
|
-
|
|
78
|
-
for (const item of fs.readdirSync(srcDir)) {
|
|
79
|
-
const srcPath = path.join(srcDir, item);
|
|
80
|
-
const destPath = path.join(destDir, item);
|
|
81
|
-
|
|
82
|
-
if (fs.statSync(srcPath).isDirectory()) {
|
|
83
|
-
copyDir(srcPath, destPath);
|
|
84
|
-
} else {
|
|
85
|
-
fs.copyFileSync(srcPath, destPath);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
67
|
module.exports = {
|
|
91
68
|
genWebpage,
|
|
92
69
|
genBootstrap,
|
package/package.json
CHANGED
package/utils.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const updatePackageName = (filePath, newName) => {
|
|
5
|
+
const content = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
6
|
+
if (content.name) {
|
|
7
|
+
content.name = newName;
|
|
8
|
+
fs.writeFileSync(filePath, JSON.stringify(content, null, 2));
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const copyDir = (srcDir, destDir) => {
|
|
13
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
14
|
+
|
|
15
|
+
for (const item of fs.readdirSync(srcDir)) {
|
|
16
|
+
const srcPath = path.join(srcDir, item);
|
|
17
|
+
const destPath = path.join(destDir, item);
|
|
18
|
+
|
|
19
|
+
if (fs.statSync(srcPath).isDirectory()) {
|
|
20
|
+
copyDir(srcPath, destPath);
|
|
21
|
+
} else {
|
|
22
|
+
fs.copyFileSync(srcPath, destPath);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
updatePackageName,
|
|
29
|
+
copyDir,
|
|
30
|
+
};
|