mdkcontroller 1.0.8 → 1.0.11

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 (3) hide show
  1. package/demoApp.js +6 -6
  2. package/main.js +17 -5
  3. package/package.json +3 -2
package/demoApp.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import svInstance from "./main.js";
2
2
  import {Router} from "express";
3
3
  // import svInstance from "mdkcontroller";
4
- import path from 'path';
5
- import {fileURLToPath} from 'url';
6
4
 
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __rootDirPath = path.dirname(__filename);
9
-
10
- const _sv = await svInstance("khanhnbd", __rootDirPath);
5
+ const cfg = {
6
+ redirectHome: function (req, res) {
7
+ res.redirect("/pages/home");
8
+ }
9
+ }
10
+ const _sv = await svInstance("khanhnbd", cfg);
11
11
  const app = _sv.server;
12
12
  const db = _sv.database;
13
13
  const authCrypt = _sv.authen;
package/main.js CHANGED
@@ -9,9 +9,15 @@ import cookieParser from "cookie-parser";
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
+ import {fileURLToPath} from "url";
13
+ import path from 'path';
12
14
  // import {privateKey, encodeMini} from "./dk_modules/dkvar.js";
13
15
 
14
- export default async function (appname, rootDirPath) {
16
+ export default async function (appname, cfgHandler = {}) {
17
+
18
+ const __filename = fileURLToPath(import.meta.url);
19
+ const __rootDirPath = path.dirname(__filename).toLowerCase();
20
+ const __parentAppPath = __rootDirPath.replace('\\node_modules\\mdkcontroller'.toLowerCase(), '');
15
21
  const app = express();
16
22
  const server = createServer(app);
17
23
  const db = await dbInstant(appname + "-Database.json");
@@ -24,7 +30,13 @@ export default async function (appname, rootDirPath) {
24
30
 
25
31
  app.use((req, res, next) => {
26
32
  res.setHeader('Cache-Control', 'no-store');
27
- if (req.url === "/") res.redirect("/pages");
33
+ if (req.url === "/") {
34
+ if (cfgHandler.redirectHome) {
35
+ cfgHandler.redirectHome(req, res);
36
+ } else {
37
+ res.redirect("/pages");
38
+ }
39
+ }
28
40
  next();
29
41
  });
30
42
 
@@ -33,7 +45,7 @@ export default async function (appname, rootDirPath) {
33
45
  switch (resultValidate) {
34
46
  case 1:
35
47
  if (req.path.toLowerCase().indexOf("/cores/login/") >= 0) {
36
- res.redirect("/pages");
48
+ res.redirect("/");
37
49
  return;
38
50
  }
39
51
  break;
@@ -47,8 +59,8 @@ export default async function (appname, rootDirPath) {
47
59
  next();
48
60
  });
49
61
 
50
- app.use("/Pages", staticExpress(join(rootDirPath, "Pages")));
51
- app.use("/Cores", staticExpress(join(rootDirPath, "Cores")));
62
+ app.use("/Pages", staticExpress(join(__parentAppPath, "Pages")));
63
+ app.use("/Cores", staticExpress(join(__rootDirPath, "Cores")));
52
64
  app.use("/api", userRoutes.router);
53
65
  return {
54
66
  server: app,
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "socket.io": "^4.7.2"
11
11
  },
12
12
  "name": "mdkcontroller",
13
- "version": "1.0.8",
13
+ "version": "1.0.11",
14
14
  "keywords": [],
15
15
  "author": "KHANHNBD <khanh272421@gmail.com>",
16
16
  "license": "ISC",
@@ -24,6 +24,7 @@
24
24
  "demoApp.js",
25
25
  "main.js",
26
26
  "Cores/",
27
- "dk_modules/"
27
+ "dk_modules/",
28
+ "Pagesa/"
28
29
  ]
29
30
  }