|
|
|
@ -1,20 +1,28 @@
|
|
|
|
|
package com.dsideal.gw;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.dsideal.gw.Contoller.IndexController;
|
|
|
|
|
import com.dsideal.gw.Handler.RouterHandler;
|
|
|
|
|
import com.dsideal.gw.Plugin.YamlProp;
|
|
|
|
|
import com.dsideal.gw.Util.LogBackLogFactory;
|
|
|
|
|
import com.jfinal.config.*;
|
|
|
|
|
import com.jfinal.kit.Prop;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.server.undertow.UndertowServer;
|
|
|
|
|
import com.jfinal.template.Engine;
|
|
|
|
|
import org.yaml.snakeyaml.Yaml;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
public class GwApplication extends JFinalConfig {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取是否为开发环境
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String getEnvPrefix() {
|
|
|
|
|
String myEnvVar = System.getenv("WORKING_ENV");
|
|
|
|
|
return myEnvVar == null ? "dev" : "pro";
|
|
|
|
@ -30,7 +38,9 @@ public class GwApplication extends JFinalConfig {
|
|
|
|
|
* 配置常量
|
|
|
|
|
*/
|
|
|
|
|
//路由表
|
|
|
|
|
public static Map<String, String> routeDict = new HashMap<>();
|
|
|
|
|
public static Map<String, String> routeList = new HashMap<>();
|
|
|
|
|
//白名单
|
|
|
|
|
public static Set<String> whiteSet = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configConstant(Constants me) {
|
|
|
|
@ -38,13 +48,19 @@ public class GwApplication extends JFinalConfig {
|
|
|
|
|
me.setLogFactory(new LogBackLogFactory());
|
|
|
|
|
//加载配置文件
|
|
|
|
|
String configFile = "application_{?}.yaml".replace("{?}", getEnvPrefix());
|
|
|
|
|
Prop prop = new YamlProp(configFile);
|
|
|
|
|
Prop PropKit = new YamlProp(configFile);
|
|
|
|
|
// 获取所有配置项,得到路由表
|
|
|
|
|
for (Map.Entry<Object, Object> entry : prop.getProperties().entrySet()) {
|
|
|
|
|
for (Map.Entry<Object, Object> entry : PropKit.getProperties().entrySet()) {
|
|
|
|
|
if (entry.getKey().toString().startsWith("route")) {
|
|
|
|
|
routeDict.put(entry.getKey().toString().substring(6), entry.getValue().toString());
|
|
|
|
|
routeList.put(entry.getKey().toString().substring(6).replace(".url",""), entry.getValue().toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 获取白名单链接列表
|
|
|
|
|
Yaml yaml = new Yaml();
|
|
|
|
|
List<String> whitelist = yaml.load(PropKit.get("whitelist"));
|
|
|
|
|
for (String url : whitelist) {
|
|
|
|
|
whiteSet.add(url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -52,7 +68,7 @@ public class GwApplication extends JFinalConfig {
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void configRoute(Routes me) {
|
|
|
|
|
|
|
|
|
|
me.add("/", IndexController.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|