mdkcontroller 1.0.5 → 1.0.8

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 +33 -4
  2. package/main.js +3 -8
  3. package/package.json +1 -1
package/demoApp.js CHANGED
@@ -1,8 +1,37 @@
1
1
  import svInstance from "./main.js";
2
+ import {Router} from "express";
3
+ // import svInstance from "mdkcontroller";
4
+ import path from 'path';
5
+ import {fileURLToPath} from 'url';
2
6
 
3
- const _sv = await svInstance("khanhnbd");
4
- const enc = await _sv.authen.encrypt("khanhnbd");
5
- const dec = await _sv.authen.decrypt(enc);
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __rootDirPath = path.dirname(__filename);
9
+
10
+ const _sv = await svInstance("khanhnbd", __rootDirPath);
11
+ const app = _sv.server;
12
+ const db = _sv.database;
13
+ const authCrypt = _sv.authen;
14
+
15
+ const tbMovie = db.data.yourTableName ?? [];
16
+
17
+ const newRouterApi = Router();
18
+ newRouterApi.get("/demoFunction/gets", authCrypt.validate, (req, res) => {
19
+ res.json({message: "Get all users"});
20
+ });
21
+ newRouterApi.get('/demoPhase2/CallNonAuth', async (req, res) => {
22
+ const accessToken = req.cookies?.access_token;
23
+ if (accessToken) {
24
+ const indexToken = tbMovie.findIndex(f => true);
25
+ tbMovie.slice(indexToken, 1);
26
+ await db.write();
27
+ }
28
+ res.redirect('/login');
29
+ });
30
+ app.use("/api", newRouterApi);
31
+
32
+
33
+ const enc = await authCrypt.encrypt("khanhnbd");
34
+ const dec = await authCrypt.decrypt(enc);
6
35
  console.log("khanhnbd => " + enc);
7
- console.log("khanhnbd will => " + dec);
36
+ console.log(enc + " will => " + dec);
8
37
  _sv.startListen(8905);
package/main.js CHANGED
@@ -5,18 +5,13 @@ import pkg_body_parser from 'body-parser';
5
5
  const {json} = pkg_body_parser;
6
6
  import {join} from "path";
7
7
  import cookieParser from "cookie-parser";
8
- import path from 'path';
9
- import {fileURLToPath} from 'url';
10
8
 
11
9
  import dbInstant from "./dk_modules/dkdb.js";
12
10
  import userInstant from "./dk_modules/users.js";
13
11
  import authInstant from "./dk_modules/authorization.js";
14
12
  // import {privateKey, encodeMini} from "./dk_modules/dkvar.js";
15
13
 
16
- export default async function (appname) {
17
- const __filename = fileURLToPath(import.meta.url);
18
- const __dirname = path.dirname(__filename);
19
-
14
+ export default async function (appname, rootDirPath) {
20
15
  const app = express();
21
16
  const server = createServer(app);
22
17
  const db = await dbInstant(appname + "-Database.json");
@@ -52,8 +47,8 @@ export default async function (appname) {
52
47
  next();
53
48
  });
54
49
 
55
- app.use("/Pages", staticExpress(join(__dirname, "Pages")));
56
- app.use("/Cores", staticExpress(join(__dirname, "Cores")));
50
+ app.use("/Pages", staticExpress(join(rootDirPath, "Pages")));
51
+ app.use("/Cores", staticExpress(join(rootDirPath, "Cores")));
57
52
  app.use("/api", userRoutes.router);
58
53
  return {
59
54
  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.5",
13
+ "version": "1.0.8",
14
14
  "keywords": [],
15
15
  "author": "KHANHNBD <khanh272421@gmail.com>",
16
16
  "license": "ISC",