You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/09/17 22:39:30 UTC

[GitHub] [apisix-dashboard] liuxiran opened a new pull request #485: feat: Route debug

liuxiran opened a new pull request #485:
URL: https://github.com/apache/apisix-dashboard/pull/485


   Please answer these questions before submitting a pull request
   
   - Why submit this pull request?
   - [ ] Bug fix
   - [ ] New feature provided
   - [ ] Improve performance
   
   - Related issues
   fix #469 
   ___
   ### Bugfix
   - Description
   
   - How to fix?
   
   ___
   ### New feature or improvement
   - Describe the details and related test reports.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] juzhiyuan merged pull request #485: feat: Route debug

Posted by GitBox <gi...@apache.org>.
juzhiyuan merged pull request #485:
URL: https://github.com/apache/apisix-dashboard/pull/485


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] liuxiran commented on a change in pull request #485: feat: Route debug

Posted by GitBox <gi...@apache.org>.
liuxiran commented on a change in pull request #485:
URL: https://github.com/apache/apisix-dashboard/pull/485#discussion_r490778454



##########
File path: src/pages/Route/transform.ts
##########
@@ -252,3 +252,131 @@ export const transformRouteData = (data: RouteModule.Body) => {
     step3Data,
   };
 };
+
+export const transformRouteDebugData = (data: RouteModule.Body) => {
+  const {
+    name,
+    desc,
+    methods,
+    uris,
+    protocols,
+    // hosts,
+    vars,
+    // redirect,
+    url,
+  } = data;
+
+  const paths = {};
+  const tags: RouteModule.TagSchema[] = [
+    {
+      name: `Route-${name}`,
+      description: desc,
+    },
+  ];
+  const servers: RouteModule.Server[] = [];
+  const responses: RouteModule.ResponseSchema = {
+    // default response code
+    '200': {
+      description: 'successful operation',
+      content: {},
+    },
+    '400': {
+      description: 'Invalid parameter',
+      content: {},
+    },
+    '500': {
+      description: 'Internal Server Error',
+      content: {},
+    },
+  };
+  const params = transformVarsToRules(vars);
+  const formatParams = params.map((param) => {
+    const { position, operator } = param;
+    let paramPostion;
+
+    switch (position) {
+      case 'cookie':
+        paramPostion = 'cookie';
+        break;
+      case 'http':
+        paramPostion = 'header';
+        break;
+      case 'arg':
+        paramPostion = 'query';
+        break;
+      default:
+        break;
+    }
+    return {
+      name: param.name,
+      in: paramPostion,
+      description: `default value should ${operator} ${param.value}`,
+      required: true,
+      type: 'string',
+    };
+  });
+  const pathParams = {
+    name: 'pathParam',
+    in: 'path',
+    description: `enter your path param`,
+    required: true,
+    type: 'string',
+  };
+  const requestBodyMethod = ['POST', 'PUT', 'PATCH'];
+
+  protocols.forEach((protocol) => {
+    if (protocol !== 'websocket') {
+      servers.push({

Review comment:
       got it 👍,thank you, and both of concat and spread syntax  have the same effect here , I perfer the latter :) 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] liuxiran commented on a change in pull request #485: feat: Route debug

Posted by GitBox <gi...@apache.org>.
liuxiran commented on a change in pull request #485:
URL: https://github.com/apache/apisix-dashboard/pull/485#discussion_r490645695



##########
File path: src/pages/Route/transform.ts
##########
@@ -252,3 +252,131 @@ export const transformRouteData = (data: RouteModule.Body) => {
     step3Data,
   };
 };
+
+export const transformRouteDebugData = (data: RouteModule.Body) => {
+  const {
+    name,
+    desc,
+    methods,
+    uris,
+    protocols,
+    // hosts,
+    vars,
+    // redirect,
+    url,
+  } = data;
+
+  const paths = {};
+  const tags: RouteModule.TagSchema[] = [
+    {
+      name: `Route-${name}`,
+      description: desc,
+    },
+  ];
+  const servers: RouteModule.Server[] = [];
+  const responses: RouteModule.ResponseSchema = {
+    // default response code
+    '200': {
+      description: 'successful operation',
+      content: {},
+    },
+    '400': {
+      description: 'Invalid parameter',
+      content: {},
+    },
+    '500': {
+      description: 'Internal Server Error',
+      content: {},
+    },
+  };
+  const params = transformVarsToRules(vars);
+  const formatParams = params.map((param) => {
+    const { position, operator } = param;
+    let paramPostion;
+
+    switch (position) {
+      case 'cookie':
+        paramPostion = 'cookie';
+        break;
+      case 'http':
+        paramPostion = 'header';
+        break;
+      case 'arg':
+        paramPostion = 'query';
+        break;
+      default:
+        break;
+    }
+    return {
+      name: param.name,
+      in: paramPostion,
+      description: `default value should ${operator} ${param.value}`,
+      required: true,
+      type: 'string',
+    };
+  });
+  const pathParams = {
+    name: 'pathParam',
+    in: 'path',
+    description: `enter your path param`,
+    required: true,
+    type: 'string',
+  };
+  const requestBodyMethod = ['POST', 'PUT', 'PATCH'];
+
+  protocols.forEach((protocol) => {
+    if (protocol !== 'websocket') {
+      servers.push({
+        url: `${protocol}://${url}`,
+      });
+      // FIXME

Review comment:
       This is a place I want to discuss with you:
   
   In the docker environment, the apisix's url returned by the manager-api is the docker ip: 192.17.5.11, which is unavailable here, so I added a url got from `window. location` as a remedy. It's easy but  not flexible🤦‍♀️,
   looking forward to your proposal @juzhiyuan 
   
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] liuxiran commented on a change in pull request #485: feat: Route debug

Posted by GitBox <gi...@apache.org>.
liuxiran commented on a change in pull request #485:
URL: https://github.com/apache/apisix-dashboard/pull/485#discussion_r490778678



##########
File path: src/pages/Route/transform.ts
##########
@@ -252,3 +252,131 @@ export const transformRouteData = (data: RouteModule.Body) => {
     step3Data,
   };
 };
+
+export const transformRouteDebugData = (data: RouteModule.Body) => {
+  const {
+    name,
+    desc,
+    methods,
+    uris,
+    protocols,
+    // hosts,
+    vars,
+    // redirect,
+    url,
+  } = data;
+
+  const paths = {};
+  const tags: RouteModule.TagSchema[] = [
+    {
+      name: `Route-${name}`,
+      description: desc,
+    },
+  ];
+  const servers: RouteModule.Server[] = [];
+  const responses: RouteModule.ResponseSchema = {
+    // default response code
+    '200': {

Review comment:
       done

##########
File path: src/pages/Route/typing.d.ts
##########
@@ -157,5 +157,70 @@ declare namespace RouteModule {
       [name: string]: any;
     };
     script: Record<string, any>;
+    url?: string;
+  };
+
+  // for route debug
+  interface Server {

Review comment:
       done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] juzhiyuan commented on a change in pull request #485: feat: Route debug

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on a change in pull request #485:
URL: https://github.com/apache/apisix-dashboard/pull/485#discussion_r490655427



##########
File path: src/pages/Route/transform.ts
##########
@@ -252,3 +252,131 @@ export const transformRouteData = (data: RouteModule.Body) => {
     step3Data,
   };
 };
+
+export const transformRouteDebugData = (data: RouteModule.Body) => {
+  const {
+    name,
+    desc,
+    methods,
+    uris,
+    protocols,
+    // hosts,
+    vars,
+    // redirect,
+    url,
+  } = data;
+
+  const paths = {};
+  const tags: RouteModule.TagSchema[] = [
+    {
+      name: `Route-${name}`,
+      description: desc,
+    },
+  ];
+  const servers: RouteModule.Server[] = [];
+  const responses: RouteModule.ResponseSchema = {
+    // default response code
+    '200': {
+      description: 'successful operation',
+      content: {},
+    },
+    '400': {
+      description: 'Invalid parameter',
+      content: {},
+    },
+    '500': {
+      description: 'Internal Server Error',
+      content: {},
+    },
+  };
+  const params = transformVarsToRules(vars);
+  const formatParams = params.map((param) => {
+    const { position, operator } = param;
+    let paramPostion;
+
+    switch (position) {
+      case 'cookie':
+        paramPostion = 'cookie';
+        break;
+      case 'http':
+        paramPostion = 'header';
+        break;
+      case 'arg':
+        paramPostion = 'query';
+        break;
+      default:
+        break;
+    }
+    return {
+      name: param.name,
+      in: paramPostion,
+      description: `default value should ${operator} ${param.value}`,
+      required: true,
+      type: 'string',
+    };
+  });
+  const pathParams = {
+    name: 'pathParam',
+    in: 'path',
+    description: `enter your path param`,
+    required: true,
+    type: 'string',
+  };
+  const requestBodyMethod = ['POST', 'PUT', 'PATCH'];
+
+  protocols.forEach((protocol) => {
+    if (protocol !== 'websocket') {
+      servers.push({
+        url: `${protocol}://${url}`,
+      });
+      // FIXME

Review comment:
       I'm not family with Docker, this issue could be discussed with @nic-chen @gxthrj @bzp2010 , if this trick way works, I think it's ok to use here.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] liuxiran commented on a change in pull request #485: feat: Route debug

Posted by GitBox <gi...@apache.org>.
liuxiran commented on a change in pull request #485:
URL: https://github.com/apache/apisix-dashboard/pull/485#discussion_r490823278



##########
File path: api/route/route.go
##########
@@ -480,6 +482,58 @@ func findRoute(c *gin.Context) {
 	}
 }
 
+func getRouteAndApisixUrl(c *gin.Context) {

Review comment:
       Refer to the naming of Apisix in other documents, updated to getRouteWithApisixUrl :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] juzhiyuan commented on a change in pull request #485: feat: Route debug

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on a change in pull request #485:
URL: https://github.com/apache/apisix-dashboard/pull/485#discussion_r490637289



##########
File path: src/pages/Route/transform.ts
##########
@@ -252,3 +252,131 @@ export const transformRouteData = (data: RouteModule.Body) => {
     step3Data,
   };
 };
+
+export const transformRouteDebugData = (data: RouteModule.Body) => {
+  const {
+    name,
+    desc,
+    methods,
+    uris,
+    protocols,
+    // hosts,
+    vars,
+    // redirect,
+    url,
+  } = data;
+
+  const paths = {};
+  const tags: RouteModule.TagSchema[] = [
+    {
+      name: `Route-${name}`,
+      description: desc,
+    },
+  ];
+  const servers: RouteModule.Server[] = [];
+  const responses: RouteModule.ResponseSchema = {
+    // default response code
+    '200': {
+      description: 'successful operation',
+      content: {},
+    },
+    '400': {
+      description: 'Invalid parameter',
+      content: {},
+    },
+    '500': {
+      description: 'Internal Server Error',
+      content: {},
+    },
+  };
+  const params = transformVarsToRules(vars);
+  const formatParams = params.map((param) => {
+    const { position, operator } = param;
+    let paramPostion;
+
+    switch (position) {
+      case 'cookie':
+        paramPostion = 'cookie';
+        break;
+      case 'http':
+        paramPostion = 'header';
+        break;
+      case 'arg':
+        paramPostion = 'query';
+        break;
+      default:
+        break;
+    }
+    return {
+      name: param.name,
+      in: paramPostion,
+      description: `default value should ${operator} ${param.value}`,
+      required: true,
+      type: 'string',
+    };
+  });
+  const pathParams = {
+    name: 'pathParam',
+    in: 'path',
+    description: `enter your path param`,
+    required: true,
+    type: 'string',
+  };
+  const requestBodyMethod = ['POST', 'PUT', 'PATCH'];
+
+  protocols.forEach((protocol) => {
+    if (protocol !== 'websocket') {
+      servers.push({

Review comment:
       `push` will take some side effects, we would recommend using `concat` instead of `push`

##########
File path: src/pages/Route/transform.ts
##########
@@ -252,3 +252,131 @@ export const transformRouteData = (data: RouteModule.Body) => {
     step3Data,
   };
 };
+
+export const transformRouteDebugData = (data: RouteModule.Body) => {
+  const {
+    name,
+    desc,
+    methods,
+    uris,
+    protocols,
+    // hosts,
+    vars,
+    // redirect,
+    url,
+  } = data;
+
+  const paths = {};
+  const tags: RouteModule.TagSchema[] = [
+    {
+      name: `Route-${name}`,
+      description: desc,
+    },
+  ];
+  const servers: RouteModule.Server[] = [];
+  const responses: RouteModule.ResponseSchema = {
+    // default response code
+    '200': {
+      description: 'successful operation',
+      content: {},
+    },
+    '400': {
+      description: 'Invalid parameter',
+      content: {},
+    },
+    '500': {
+      description: 'Internal Server Error',
+      content: {},
+    },
+  };
+  const params = transformVarsToRules(vars);
+  const formatParams = params.map((param) => {
+    const { position, operator } = param;
+    let paramPostion;
+
+    switch (position) {
+      case 'cookie':
+        paramPostion = 'cookie';
+        break;
+      case 'http':
+        paramPostion = 'header';
+        break;
+      case 'arg':
+        paramPostion = 'query';
+        break;
+      default:
+        break;
+    }
+    return {
+      name: param.name,
+      in: paramPostion,
+      description: `default value should ${operator} ${param.value}`,
+      required: true,
+      type: 'string',
+    };
+  });
+  const pathParams = {
+    name: 'pathParam',
+    in: 'path',
+    description: `enter your path param`,
+    required: true,
+    type: 'string',
+  };
+  const requestBodyMethod = ['POST', 'PUT', 'PATCH'];
+
+  protocols.forEach((protocol) => {
+    if (protocol !== 'websocket') {
+      servers.push({
+        url: `${protocol}://${url}`,
+      });
+      // FIXME

Review comment:
       what happened here?

##########
File path: src/pages/Route/transform.ts
##########
@@ -252,3 +252,131 @@ export const transformRouteData = (data: RouteModule.Body) => {
     step3Data,
   };
 };
+
+export const transformRouteDebugData = (data: RouteModule.Body) => {
+  const {
+    name,
+    desc,
+    methods,
+    uris,
+    protocols,
+    // hosts,
+    vars,
+    // redirect,
+    url,
+  } = data;
+
+  const paths = {};
+  const tags: RouteModule.TagSchema[] = [
+    {
+      name: `Route-${name}`,
+      description: desc,
+    },
+  ];
+  const servers: RouteModule.Server[] = [];
+  const responses: RouteModule.ResponseSchema = {
+    // default response code
+    '200': {

Review comment:
       could we use `ok` here? https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200

##########
File path: src/pages/Route/typing.d.ts
##########
@@ -157,5 +157,70 @@ declare namespace RouteModule {
       [name: string]: any;
     };
     script: Record<string, any>;
+    url?: string;
+  };
+
+  // for route debug
+  interface Server {

Review comment:
       please use `type` instead of `interface` to prevent from type override :D

##########
File path: api/route/route.go
##########
@@ -480,6 +482,58 @@ func findRoute(c *gin.Context) {
 	}
 }
 
+func getRouteAndApisixUrl(c *gin.Context) {

Review comment:
       could we use camelCase here? e.g `getRouteWithAPISIXURL` .




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org