yaml-admin-api 0.0.52 → 0.0.53

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml-admin-api",
3
- "version": "0.0.52",
3
+ "version": "0.0.53",
4
4
  "license": "MIT",
5
5
  "description": "YAML Admin API package",
6
6
  "type": "commonjs",
@@ -8,7 +8,7 @@ const { makeMongoSortFromYml } = require('./crud-common.js');
8
8
  * @param {*} db
9
9
  * @param {*} yml
10
10
  */
11
- const generateChartApi = async (app, db, yml) => {
11
+ const generateChartApi = async (app, db, yml, prefix) => {
12
12
  const { front } = yml;
13
13
  const dashboard = front?.dashboard;
14
14
  if (!dashboard)
@@ -281,7 +281,7 @@ const generateChartApi = async (app, db, yml) => {
281
281
  /**
282
282
  * TODO : globalFilterDelegate not implemented
283
283
  */
284
- app.get(`/api/chart/${id}`, auth.isAuthenticated, async (req, res) => {
284
+ app.get(`${prefix}/api/chart/${id}`, auth.isAuthenticated, async (req, res) => {
285
285
  try {
286
286
  const { x } = chart;
287
287
  let r
@@ -1,8 +1,8 @@
1
1
  const member = require('../member/member.js');
2
2
 
3
- const generateLoginApi = async(app, db, yml) => {
3
+ const generateLoginApi = async(app, db, yml, prefix) => {
4
4
  console.log('generateLoginApi', yml.login["jwt-secret"])
5
- await member(app, db, yml)
5
+ await member(app, db, yml, prefix)
6
6
  }
7
7
 
8
8
  module.exports = {
@@ -1,32 +1,36 @@
1
1
  const {withConfig} = require('../login/auth.js');
2
2
 
3
- module.exports = async function (app, db, yml, delegate) {
3
+ module.exports = async function (app, db, yml, prefix) {
4
4
  const auth = withConfig({ db, jwt_secret: yml.login["jwt-secret"], passwordEncoding: yml.login["password-encoding"] });
5
5
 
6
- app.get('/member/login',
6
+ app.get(prefix + '/member/login',
7
7
  auth.authenticate,
8
8
  function (req, res) {
9
9
  res.json({ r: true, token: req.token, member: req.user });
10
10
  }
11
11
  );
12
12
 
13
- app.get('/member/islogin',
13
+ app.get(prefix + '/member/islogin',
14
14
  auth.isAuthenticated,
15
15
  async function (req, res) {
16
16
  res.json({ r: true, member: req.user });
17
17
  }
18
18
  );
19
19
 
20
- app.post('/member/login',
20
+ app.post(prefix + '/member/login',
21
21
  auth.authenticate,
22
22
  function (req, res) {
23
23
  res.json({ r: true, token: req.token, member: req.user });
24
24
  }
25
25
  );
26
26
 
27
- app.get('/member/logout', async (req, res) => {
27
+ app.get(prefix + '/member/logout', async (req, res) => {
28
28
  req.logout();
29
29
  res.json({ r: true });
30
30
  });
31
31
 
32
+ app.get(prefix + '/member/test', async (req, res) => {
33
+ res.json({ r: true });
34
+ });
35
+
32
36
  };
@@ -18,7 +18,7 @@ const changeEnv = (yamlString, env = {}) => {
18
18
  }
19
19
 
20
20
  async function registerRoutes(app, options = {}) {
21
- const { yamlPath, yamlString, env, yamlJson } = options;
21
+ const { yamlPath, yamlString, env, yamlJson, prefix } = options;
22
22
  let yml;
23
23
 
24
24
  if(yamlJson) {
@@ -50,8 +50,8 @@ async function registerRoutes(app, options = {}) {
50
50
  }
51
51
  }
52
52
 
53
- await generateLoginApi(app, db, yml)
54
- await generateChartApi(app, db, yml)
53
+ await generateLoginApi(app, db, yml, prefix)
54
+ await generateChartApi(app, db, yml, prefix)
55
55
 
56
56
  entity && Object.keys(entity).forEach(async (entity_name) => {
57
57
  await generateEntityApi({