You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.8 KiB

10 months ago
package com.dsideal.gw;
3 months ago
import cn.hutool.core.io.FileUtil;
2 months ago
import com.dsideal.Config.PropKit;
10 months ago
import com.dsideal.gw.Contoller.IndexController;
10 months ago
import com.dsideal.gw.Handler.RouterHandler;
import com.dsideal.gw.Util.LogBackLogFactory;
10 months ago
import com.jfinal.config.*;
3 months ago
import com.jfinal.plugin.redis.RedisPlugin;
10 months ago
import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;
9 months ago
import lombok.SneakyThrows;
3 months ago
import org.slf4j.LoggerFactory;
10 months ago
import org.yaml.snakeyaml.Yaml;
10 months ago
10 months ago
import java.util.*;
3 months ago
import org.slf4j.Logger;
10 months ago
public class GwApplication extends JFinalConfig {
3 months ago
private static final Logger logger = LoggerFactory.getLogger(GwApplication.class);
2 months ago
10 months ago
public static void main(String[] args) {
2 months ago
System.out.println("当前环境: " + PropKit.getEnvPrefix());
3 months ago
String configFile = "undertow.properties";
10 months ago
UndertowServer.create(GwApplication.class, configFile).start();
}
10 months ago
10 months ago
//路由表
10 months ago
public static Map<String, String> routeList = new HashMap<>();
//白名单
public static Set<String> whiteSet = new HashSet<>();
10 months ago
10 months ago
/**
*
*/
10 months ago
@Override
public void configConstant(Constants me) {
10 months ago
//使用LogBack
me.setLogFactory(new LogBackLogFactory());
10 months ago
10 months ago
// 获取所有配置项,得到路由表
10 months ago
for (Map.Entry<Object, Object> entry : PropKit.getProperties().entrySet()) {
10 months ago
if (entry.getKey().toString().startsWith("route")) {
10 months ago
routeList.put(entry.getKey().toString().substring(6).replace(".url", ""), entry.getValue().toString());
10 months ago
}
}
10 months ago
// 获取白名单链接列表
Yaml yaml = new Yaml();
List<String> whitelist = yaml.load(PropKit.get("whitelist"));
10 months ago
whiteSet.addAll(whitelist);
10 months ago
}
/**
*
*/
@Override
public void configRoute(Routes me) {
10 months ago
me.add("/", IndexController.class);
10 months ago
}
@Override
public void configEngine(Engine engine) {
}
@Override
public void configPlugin(Plugins me) {
3 months ago
//加载Redis插件
RedisPlugin redis = new RedisPlugin("Redis", PropKit.get("redis.ip"),PropKit.getInt("redis.port"), 10000);
me.add(redis);
10 months ago
}
/**
*
*/
@Override
public void configInterceptor(Interceptors me) {
}
/**
*
*/
@Override
public void configHandler(Handlers me) {
10 months ago
//路由处理器
10 months ago
me.add(new RouterHandler());
10 months ago
}
10 months ago
10 months ago
/**
* jfinal
*/
9 months ago
@SneakyThrows
10 months ago
@Override
public void onStart() {
//打印 启动Logo
3 months ago
System.out.println(FileUtil.readUtf8String("logo.txt"));
10 months ago
}
}