86
86
import apijson .orm .JSONRequest ;
87
87
import apijson .orm .model .TestRecord ;
88
88
import apijson .router .APIJSONRouterController ;
89
+ import org .springframework .web .servlet .ModelAndView ;
89
90
import unitauto .MethodUtil ;
90
91
91
92
import static apijson .RequestMethod .DELETE ;
@@ -128,9 +129,30 @@ public class DemoController extends APIJSONRouterController<Long> { // APIJSONC
128
129
// 可以更方便地通过日志排查错误
129
130
@ Override
130
131
public String getRequestURL () {
131
- return httpServletRequest .getRequestURL ().toString ();
132
+ HttpServletRequest httpReq = httpServletRequest ;
133
+
134
+ String path = httpReq .getServletPath ();
135
+ int index = path .lastIndexOf ("/" );
136
+ path = index < 0 ? path : path .substring (0 , index );
137
+ String host = httpReq .getHeader ("origin" );
138
+ if (StringUtil .isEmpty (host )) {
139
+ host = httpReq .getHeader ("host" );
140
+ String prefix = httpReq .getProtocol ().trim ().toLowerCase ().contains ("https" ) ? "https://" : "http://" ;
141
+ if (StringUtil .isEmpty (host )) {
142
+ host = prefix + httpReq .getServerName () + ":" + httpReq .getServerPort ();
143
+ } else {
144
+ host = prefix + host ;
145
+ }
146
+ }
147
+
148
+ return host + path ;
132
149
}
133
150
151
+ // @Override
152
+ // public Parser<Long> newParser(HttpSession session, RequestMethod method) {
153
+ // return super.newParser(session, method).setNeedVerify(false);
154
+ // }
155
+
134
156
/**增删改查统一的类 RESTful API 入口,牺牲一点路由解析性能来提升一些开发效率
135
157
* @param method
136
158
* @param tag
@@ -385,24 +407,9 @@ public String openGet(@PathVariable("request") String request, HttpSession sessi
385
407
// 以下代码是为了方便调试,引导手动/自动跳转 http://apijson.cn/api 来测试接口
386
408
String newUrl = null ;
387
409
try {
388
- HttpServletRequest httpReq = httpServletRequest ;
410
+ String url = getRequestURL () ;
389
411
390
- String path = httpReq .getServletPath ();
391
- int index = path .lastIndexOf ("/" );
392
- path = index < 0 ? path : path .substring (0 , index );
393
- String host = httpReq .getHeader ("origin" );
394
- if (StringUtil .isEmpty (host )) {
395
- host = httpReq .getHeader ("host" );
396
- String prefix = httpReq .getProtocol ().trim ().toLowerCase ().contains ("https" ) ? "https://" : "http://" ;
397
- if (StringUtil .isEmpty (host )) {
398
- host = prefix + httpReq .getServerName () + ":" + httpReq .getServerPort ();
399
- } else {
400
- host = prefix + host ;
401
- }
402
- }
403
-
404
- String url = host + path ;
405
- String query = StringUtil .getTrimedString (httpReq .getQueryString ());
412
+ String query = StringUtil .getTrimedString (httpServletRequest .getQueryString ());
406
413
if (StringUtil .isNotEmpty (query )) {
407
414
try {
408
415
query = "?" + URLEncoder .encode (query , StandardCharsets .UTF_8 );
@@ -412,7 +419,7 @@ public String openGet(@PathVariable("request") String request, HttpSession sessi
412
419
}
413
420
}
414
421
415
- newUrl = "http://apijson.cn/api?send=false&redirect=false&type=JSON&unquote =true&url="
422
+ newUrl = "http://apijson.cn/api?send=false&redirect=false&type=JSON&decode =true&url="
416
423
+ url + query + "&json=" + request ;
417
424
418
425
// httpServletResponse.setHeader("Referer", newUrl);
@@ -2724,6 +2731,50 @@ public String rapRepositoryDetail(@RequestParam("id") String id) {
2724
2731
// 为 APIAuto 提供的代理接口(解决跨域问题) 和 导入第三方文档的测试接口 https://github.com/TommyLemon/APIAuto https://github.com/TommyLemon/APIAuto >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2725
2732
2726
2733
2734
+ // 为 APIAuto, UnitAuto, SQLAuto, UIGO 提供网页入口 <<<<<<<<<<<<<<<<<<<<<<<<<<<
2735
+ @ GetMapping ("api" )
2736
+ public String api () {
2737
+ try {
2738
+ httpServletResponse .sendRedirect ("/api/index.html" );
2739
+ } catch (Throwable e ) {
2740
+ e .printStackTrace ();
2741
+ }
2742
+ return "forward:/api/index.html" ; // 两者都无效 "redirect:/api/index.html";
2743
+ }
2744
+
2745
+ @ GetMapping ("unit" )
2746
+ public String unit () {
2747
+ try {
2748
+ httpServletResponse .sendRedirect ("/unit/index.html" );
2749
+ } catch (Throwable e ) {
2750
+ e .printStackTrace ();
2751
+ }
2752
+ return "forward:/unit/index.html" ; // 两者都无效 "redirect:/unit/index.html";
2753
+ }
2754
+
2755
+ @ GetMapping ("sql" )
2756
+ public String sql () {
2757
+ try {
2758
+ httpServletResponse .sendRedirect ("/sql/index.html" );
2759
+ } catch (Throwable e ) {
2760
+ e .printStackTrace ();
2761
+ }
2762
+ return "forward:/ui/index.html" ; // 加载不了完整网页 return new ModelAndView("forward:/sql/index.html");
2763
+ }
2764
+
2765
+ @ GetMapping ("ui" )
2766
+ public String ui () {
2767
+ try {
2768
+ httpServletResponse .sendRedirect ("/ui/index.html" );
2769
+ } catch (Throwable e ) {
2770
+ e .printStackTrace ();
2771
+ }
2772
+ return "forward:/ui/index.html" ; // 两者都无效 "redirect:/ui/index.html";
2773
+ }
2774
+
2775
+ // 为 APIAuto, UnitAuto, SQLAuto, UIGO 提供网页入口 >>>>>>>>>>>>>>>>>>>>>>>>>>>
2776
+
2777
+
2727
2778
2728
2779
// 为 UnitAuto 提供的单元测试接口 https://github.com/TommyLemon/UnitAuto <<<<<<<<<<<<<<<<<<<<<<<<<<<
2729
2780
@@ -2739,7 +2790,6 @@ public void invokeMethod(@RequestBody String request, HttpServletRequest servlet
2739
2790
2740
2791
// 为 UnitAuto 提供的单元测试接口 https://github.com/TommyLemon/UnitAuto >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2741
2792
2742
-
2743
2793
// 为 APIAuto, UnitAuto, SQLAuto 提供的后台 Headless 无 UI 测试转发接口 <<<<<<<<<<<<<<<<<<<<<<<<<<<
2744
2794
2745
2795
@ GetMapping ("api/test/start" )
0 commit comments