mdkcontroller 1.3.1 → 1.3.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/main.js +18 -6
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import express, {Router, static as staticExpress} from "express";
|
|
2
|
-
import {createServer} from "http";
|
|
1
|
+
import express, { Router, static as staticExpress } from "express";
|
|
2
|
+
import { createServer } from "http";
|
|
3
3
|
import pkg_body_parser from 'body-parser';
|
|
4
4
|
|
|
5
|
-
const {json} = pkg_body_parser;
|
|
6
|
-
import {join} from "path";
|
|
5
|
+
const { json } = pkg_body_parser;
|
|
6
|
+
import { join } from "path";
|
|
7
7
|
import cookieParser from "cookie-parser";
|
|
8
8
|
|
|
9
9
|
import dbInstant from "./dk_modules/dkdb.js";
|
|
10
10
|
import userInstant from "./dk_modules/users.js";
|
|
11
11
|
import authInstant from "./dk_modules/authorization.js";
|
|
12
12
|
|
|
13
|
-
import {fileURLToPath} from "url";
|
|
13
|
+
import { fileURLToPath } from "url";
|
|
14
14
|
import path from 'path';
|
|
15
15
|
|
|
16
16
|
export default async function (appname, cfgHandler = {}) {
|
|
@@ -23,6 +23,18 @@ export default async function (appname, cfgHandler = {}) {
|
|
|
23
23
|
const db = await dbInstant(appname + "-Database.json");
|
|
24
24
|
const auth = authInstant();
|
|
25
25
|
const userRoutes = userInstant(Router(), db);
|
|
26
|
+
global.db = db;
|
|
27
|
+
global.app = app;
|
|
28
|
+
global.auth = auth;
|
|
29
|
+
global.generateRandomString = (length = 8) => {
|
|
30
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
31
|
+
let result = '';
|
|
32
|
+
const charactersLength = characters.length;
|
|
33
|
+
for (let i = 0; i < length; i++) {
|
|
34
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
35
|
+
}
|
|
36
|
+
return result.toUpperCase();
|
|
37
|
+
};
|
|
26
38
|
|
|
27
39
|
app.use(json());
|
|
28
40
|
app.use(cookieParser());
|
|
@@ -69,7 +81,7 @@ export default async function (appname, cfgHandler = {}) {
|
|
|
69
81
|
server: app,
|
|
70
82
|
database: db,
|
|
71
83
|
authen: auth,
|
|
72
|
-
serverBase
|
|
84
|
+
serverBase: server,
|
|
73
85
|
startListen:
|
|
74
86
|
function (kport = 8095) {
|
|
75
87
|
server.listen(kport, () => {
|