changes (still bugs :c)
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
package net.miarma.contaminus;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
import io.vertx.core.Launcher;
|
||||
import io.vertx.core.impl.logging.LoggerFactory;
|
||||
import net.miarma.contaminus.common.Constants;
|
||||
import net.miarma.contaminus.common.OSType;
|
||||
import net.miarma.contaminus.server.MainVerticle;
|
||||
import net.miarma.contaminus.util.SystemUtil;
|
||||
|
||||
public class ContaminUS {
|
||||
public static void main(String[] args) {
|
||||
initializeConstants();
|
||||
initializeDirectories();
|
||||
copyDefaultConfig();
|
||||
|
||||
Launcher.executeCommand("run", MainVerticle.class.getName());
|
||||
}
|
||||
|
||||
private static void initializeConstants() {
|
||||
Constants.HOME_DIR = SystemUtil.getOS() == OSType.WINDOWS ?
|
||||
"C:/Users/" + System.getProperty("user.name") + "/" :
|
||||
System.getProperty("user.home").contains("root") ? "/root/" :
|
||||
"/home/" + System.getProperty("user.name") + "/";
|
||||
|
||||
Constants.BASE_DIR = Constants.HOME_DIR +
|
||||
(SystemUtil.getOS() == OSType.WINDOWS ? ".contaminus" :
|
||||
SystemUtil.getOS() == OSType.LINUX ? ".config/contaminus" :
|
||||
".contaminus");
|
||||
|
||||
Constants.CONFIG_FILE = Constants.BASE_DIR + "/config.properties";
|
||||
System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
|
||||
Constants.LOGGER = LoggerFactory.getLogger(Constants.APP_NAME);
|
||||
}
|
||||
|
||||
private static void initializeDirectories() {
|
||||
File baseDir = new File(Constants.BASE_DIR);
|
||||
if (!baseDir.exists()) {
|
||||
baseDir.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyDefaultConfig() {
|
||||
File configFile = new File(Constants.CONFIG_FILE);
|
||||
if (!configFile.exists()) {
|
||||
try (InputStream in = MainVerticle.class.getClassLoader().getResourceAsStream("default.properties")) {
|
||||
if (in != null) {
|
||||
Files.copy(in, configFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
} else {
|
||||
Constants.LOGGER.error("Default config file not found in resources");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Constants.LOGGER.error("Failed to copy default config file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,21 +4,20 @@ import java.io.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ConfigManager {
|
||||
private static ConfigManager instance;
|
||||
private static final ConfigManager INSTANCE = new ConfigManager();
|
||||
private final File configFile;
|
||||
private final Properties config;
|
||||
private static final String CONFIG_FILE_NAME = "config.properties";
|
||||
|
||||
private ConfigManager() {
|
||||
this.configFile = new File(Constants.CONFIG_FILE);
|
||||
String path = getBaseDir() + CONFIG_FILE_NAME;
|
||||
this.configFile = new File(path);
|
||||
this.config = new Properties();
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
public static synchronized ConfigManager getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ConfigManager();
|
||||
}
|
||||
return instance;
|
||||
public static ConfigManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
@@ -28,25 +27,70 @@ public class ConfigManager {
|
||||
Constants.LOGGER.error("Error loading configuration file: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
public File getConfigFile() {
|
||||
return configFile;
|
||||
}
|
||||
|
||||
public String getJdbcUrl() {
|
||||
return String.format("%s://%s:%s/%s",
|
||||
config.getProperty("db.protocol"),
|
||||
config.getProperty("db.host"),
|
||||
config.getProperty("db.port"),
|
||||
config.getProperty("db.name"));
|
||||
return String.format("%s://%s:%s/%s",
|
||||
config.getProperty("db.protocol"),
|
||||
config.getProperty("db.host"),
|
||||
config.getProperty("db.port"),
|
||||
config.getProperty("db.name"));
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return this.getStringProperty("inet.host");
|
||||
}
|
||||
|
||||
public int getDataApiPort() {
|
||||
return this.getIntProperty("data-api.port");
|
||||
}
|
||||
|
||||
public int getLogicApiPort() {
|
||||
return this.getIntProperty("logic-api.port");
|
||||
}
|
||||
|
||||
public int getWebserverPort() {
|
||||
return this.getIntProperty("web.port");
|
||||
}
|
||||
|
||||
public String getHomeDir() {
|
||||
return getOS() == OSType.WINDOWS ?
|
||||
"C:/Users/" + System.getProperty("user.name") + "/" :
|
||||
System.getProperty("user.home").contains("root") ? "/root/" :
|
||||
"/home/" + System.getProperty("user.name") + "/";
|
||||
}
|
||||
|
||||
public String getBaseDir() {
|
||||
return getHomeDir() +
|
||||
(getOS() == OSType.WINDOWS ? ".contaminus" :
|
||||
getOS() == OSType.LINUX ? ".config/contaminus" :
|
||||
".contaminus");
|
||||
}
|
||||
|
||||
public static OSType getOS() {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
if (os.contains("win")) {
|
||||
return OSType.WINDOWS;
|
||||
} else if (os.contains("nix") || os.contains("nux")) {
|
||||
return OSType.LINUX;
|
||||
} else {
|
||||
return OSType.INVALID_OS;
|
||||
}
|
||||
}
|
||||
|
||||
public String getStringProperty(String key) {
|
||||
return config.getProperty(key);
|
||||
}
|
||||
|
||||
public int getIntProperty(String key) {
|
||||
return Integer.parseInt(config.getProperty(key));
|
||||
}
|
||||
return Integer.parseInt(config.getProperty(key));
|
||||
}
|
||||
|
||||
public boolean getBooleanProperty(String key) {
|
||||
return Boolean.parseBoolean(config.getProperty(key));
|
||||
return Boolean.parseBoolean(config.getProperty(key));
|
||||
}
|
||||
|
||||
public void setProperty(String key, String value) {
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
package net.miarma.contaminus.common;
|
||||
|
||||
import io.vertx.core.impl.logging.Logger;
|
||||
import net.miarma.contaminus.database.DatabaseManager;
|
||||
import io.vertx.core.impl.logging.LoggerFactory;
|
||||
|
||||
public class Constants {
|
||||
public static final String APP_NAME = "ContaminUS";
|
||||
public static final int API_VERSION = 1;
|
||||
public static final String API_PREFIX = "/api/v" + Constants.API_VERSION;
|
||||
public static String HOME_DIR;
|
||||
public static String BASE_DIR;
|
||||
public static String CONFIG_FILE;
|
||||
public static ConfigManager CONFIG;
|
||||
public static DatabaseManager DB;
|
||||
public static Logger LOGGER;
|
||||
public static Logger LOGGER = LoggerFactory.getLogger(Constants.APP_NAME);
|
||||
|
||||
|
||||
/* API Endpoints */
|
||||
public static final String GET_GROUPS = API_PREFIX + "/groups";
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package net.miarma.contaminus.database;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.Vertx;
|
||||
@@ -15,52 +10,61 @@ import io.vertx.sqlclient.RowSet;
|
||||
import net.miarma.contaminus.common.ConfigManager;
|
||||
import net.miarma.contaminus.common.Constants;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DatabaseManager {
|
||||
private final JDBCPool pool;
|
||||
private static DatabaseManager instance;
|
||||
private final JDBCPool pool;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public DatabaseManager(Vertx vertx) {
|
||||
private DatabaseManager(Vertx vertx) {
|
||||
ConfigManager config = ConfigManager.getInstance();
|
||||
|
||||
JsonObject dbConfig = new JsonObject()
|
||||
.put("url", config.getStringProperty("db.protocol") + "//" +
|
||||
config.getStringProperty("db.host") + ":" +
|
||||
config.getStringProperty("db.port") + "/" +
|
||||
config.getStringProperty("db.name"))
|
||||
.put("user", config.getStringProperty("db.user"))
|
||||
.put("password", config.getStringProperty("db.pwd"))
|
||||
.put("max_pool_size", config.getStringProperty("db.poolSize"));
|
||||
.put("jdbcUrl", config.getJdbcUrl())
|
||||
.put("username", config.getStringProperty("db.user"))
|
||||
.put("password", config.getStringProperty("db.pwd"))
|
||||
.put("max_pool_size", config.getIntProperty("db.poolSize"));
|
||||
|
||||
pool = JDBCPool.pool(vertx, dbConfig);
|
||||
}
|
||||
|
||||
public Future<RowSet<Row>> testConnection() {
|
||||
return pool.query("SELECT 1").execute();
|
||||
}
|
||||
public static synchronized DatabaseManager getInstance(Vertx vertx) {
|
||||
if (instance == null) {
|
||||
instance = new DatabaseManager(vertx);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public <T> Future<List<T>> execute(String query, Class<T> clazz,
|
||||
Handler<List<T>> onSuccess, Handler<Throwable> onFailure) {
|
||||
public Future<RowSet<Row>> testConnection() {
|
||||
return pool.query("SELECT 1").execute();
|
||||
}
|
||||
|
||||
return pool.query(query).execute()
|
||||
.map(rows -> {
|
||||
List<T> results = new ArrayList<>();
|
||||
for (Row row : rows) {
|
||||
try {
|
||||
Constructor<T> constructor = clazz.getConstructor(Row.class);
|
||||
results.add(constructor.newInstance(row));
|
||||
} catch (NoSuchMethodException | InstantiationException |
|
||||
IllegalAccessException | InvocationTargetException e) {
|
||||
Constants.LOGGER.error("Error instantiating class: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return results;
|
||||
})
|
||||
.onComplete(ar -> {
|
||||
if (ar.succeeded()) {
|
||||
onSuccess.handle(ar.result());
|
||||
} else {
|
||||
onFailure.handle(ar.cause());
|
||||
}
|
||||
});
|
||||
}
|
||||
public <T> Future<List<T>> execute(String query, Class<T> clazz,
|
||||
Handler<List<T>> onSuccess, Handler<Throwable> onFailure) {
|
||||
return pool.query(query).execute()
|
||||
.map(rows -> {
|
||||
List<T> results = new ArrayList<>();
|
||||
for (Row row : rows) {
|
||||
try {
|
||||
Constructor<T> constructor = clazz.getConstructor(Row.class);
|
||||
results.add(constructor.newInstance(row));
|
||||
} catch (NoSuchMethodException | InstantiationException |
|
||||
IllegalAccessException | InvocationTargetException e) {
|
||||
Constants.LOGGER.error("Error instantiating class: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return results;
|
||||
})
|
||||
.onComplete(ar -> {
|
||||
if (ar.succeeded()) {
|
||||
onSuccess.handle(ar.result());
|
||||
} else {
|
||||
onFailure.handle(ar.cause());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,22 +17,17 @@ import io.vertx.ext.web.handler.CorsHandler;
|
||||
import net.miarma.contaminus.common.ConfigManager;
|
||||
import net.miarma.contaminus.common.Constants;
|
||||
import net.miarma.contaminus.database.DatabaseManager;
|
||||
import net.miarma.contaminus.util.SystemUtil;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class DataLayerAPIVerticle extends AbstractVerticle {
|
||||
private DatabaseManager dbManager;
|
||||
private Gson gson;
|
||||
private ConfigManager configManager;
|
||||
private DatabaseManager dbManager = DatabaseManager.getInstance(vertx);
|
||||
private Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
|
||||
private ConfigManager configManager = ConfigManager.getInstance();
|
||||
|
||||
@Override
|
||||
public void start(Promise<Void> startPromise) {
|
||||
Constants.LOGGER.info("📡 Iniciando DataLayerAPIVerticle...");
|
||||
|
||||
configManager = ConfigManager.getInstance();
|
||||
gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
|
||||
dbManager = new DatabaseManager(vertx);
|
||||
|
||||
|
||||
Router router = Router.router(vertx);
|
||||
Set<HttpMethod> allowedMethods = new HashSet<>(
|
||||
Arrays.asList(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.OPTIONS)); // Por ejemplo
|
||||
@@ -71,30 +66,18 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
|
||||
dbManager.testConnection()
|
||||
.onSuccess(rows -> {
|
||||
Constants.LOGGER.info("✅ Database connection ok");
|
||||
Constants.LOGGER.info("🟢 DataAccessVerticle desplegado");
|
||||
vertx.createHttpServer()
|
||||
.requestHandler(router)
|
||||
.listen(configManager.getDataApiPort(), configManager.getHost());
|
||||
startPromise.complete();
|
||||
})
|
||||
.onFailure(onFailure -> {
|
||||
Constants.LOGGER.error("❌ Database connection failed");
|
||||
Constants.LOGGER.error("🔴 Error al desplegar DataAccessVerticle", onFailure);
|
||||
Throwable t = onFailure.getCause();
|
||||
t.printStackTrace();
|
||||
startPromise.fail(onFailure);
|
||||
});
|
||||
|
||||
vertx.createHttpServer()
|
||||
.requestHandler(router)
|
||||
.listen(SystemUtil.getDataApiPort(), result -> {
|
||||
if (result.succeeded()) {
|
||||
Constants.LOGGER.info(String.format(
|
||||
"🟢 DataLayerAPIVerticle desplegado. (http://%s:%d)",
|
||||
SystemUtil.getHost(), SystemUtil.getDataApiPort()
|
||||
));
|
||||
startPromise.complete();
|
||||
} else {
|
||||
Constants.LOGGER.error("🔴 Error al desplegar DataLayerAPIVerticle", result.cause());
|
||||
startPromise.fail(result.cause());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void getAllGroups(RoutingContext context) {
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package net.miarma.contaminus.server;
|
||||
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
import io.vertx.ext.web.Router;
|
||||
import io.vertx.ext.web.handler.StaticHandler;
|
||||
import net.miarma.contaminus.common.Constants;
|
||||
import net.miarma.contaminus.util.SystemUtil;
|
||||
|
||||
public class HttpServerVerticle extends AbstractVerticle {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
Constants.LOGGER.info("📡 Iniciando HttpServerVerticle...");
|
||||
|
||||
Router router = Router.router(vertx);
|
||||
|
||||
router.route("/*")
|
||||
.handler(
|
||||
StaticHandler.create("webroot")
|
||||
.setDefaultContentEncoding("UTF-8")
|
||||
);
|
||||
|
||||
router.route("/dashboard/*").handler(ctx -> {
|
||||
ctx.reroute("/index.html");
|
||||
});
|
||||
|
||||
vertx.createHttpServer().requestHandler(router).listen(
|
||||
SystemUtil.getWebserverPort(), SystemUtil.getHost(), result -> {
|
||||
if (result.succeeded()) {
|
||||
Constants.LOGGER.info(String.format("🟢 HttpServerVerticle desplegado. (http://%s:%d)",
|
||||
SystemUtil.getHost(), SystemUtil.getWebserverPort())
|
||||
);
|
||||
} else {
|
||||
Constants.LOGGER.error("🔴 Error al desplegar HttpServerVerticle", result.cause());
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -18,21 +18,16 @@ import io.vertx.ext.web.handler.CorsHandler;
|
||||
import net.miarma.contaminus.common.ConfigManager;
|
||||
import net.miarma.contaminus.common.Constants;
|
||||
import net.miarma.contaminus.database.DatabaseManager;
|
||||
import net.miarma.contaminus.util.SystemUtil;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||
private DatabaseManager dbManager;
|
||||
private Gson gson;
|
||||
private ConfigManager configManager;
|
||||
private DatabaseManager dbManager = DatabaseManager.getInstance(vertx);
|
||||
private Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
|
||||
private ConfigManager configManager = ConfigManager.getInstance();
|
||||
|
||||
@Override
|
||||
public void start(Promise<Void> startPromise) {
|
||||
Constants.LOGGER.info("📡 Iniciando LogicApiVerticle...");
|
||||
|
||||
configManager = ConfigManager.getInstance();
|
||||
gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
|
||||
dbManager = new DatabaseManager(vertx);
|
||||
|
||||
Router router = Router.router(vertx);
|
||||
Set<HttpMethod> allowedMethods = new HashSet<>(
|
||||
@@ -60,20 +55,9 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||
|
||||
vertx.createHttpServer()
|
||||
.requestHandler(router)
|
||||
.listen(
|
||||
SystemUtil.getLogicApiPort(),
|
||||
SystemUtil.getHost(),
|
||||
result -> {
|
||||
if (result.succeeded()) {
|
||||
Constants.LOGGER.info(String.format(
|
||||
"🟢 ApiVerticle desplegado. (http://%s:%d)", SystemUtil.getHost(), SystemUtil.getLogicApiPort()
|
||||
));
|
||||
startPromise.complete();
|
||||
} else {
|
||||
Constants.LOGGER.error("🔴 Error al desplegar LogicApiVerticle", result.cause());
|
||||
startPromise.fail(result.cause());
|
||||
}
|
||||
});
|
||||
.listen(configManager.getLogicApiPort(), configManager.getHost());
|
||||
|
||||
startPromise.complete();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,20 +1,87 @@
|
||||
package net.miarma.contaminus.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
import io.vertx.core.DeploymentOptions;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.ThreadingModel;
|
||||
import net.miarma.contaminus.common.ConfigManager;
|
||||
import net.miarma.contaminus.common.Constants;
|
||||
|
||||
public class MainVerticle extends AbstractVerticle {
|
||||
static ConfigManager configManager = ConfigManager.getInstance();
|
||||
|
||||
private void init() {
|
||||
initializeDirectories();
|
||||
copyDefaultConfig();
|
||||
}
|
||||
|
||||
private static void initializeDirectories() {
|
||||
File baseDir = new File(configManager.getBaseDir());
|
||||
if (!baseDir.exists()) {
|
||||
baseDir.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyDefaultConfig() {
|
||||
File configFile = new File(configManager.getConfigFile().getAbsolutePath());
|
||||
if (!configFile.exists()) {
|
||||
try (InputStream in = MainVerticle.class.getClassLoader().getResourceAsStream("default.properties")) {
|
||||
if (in != null) {
|
||||
Files.copy(in, configFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
} else {
|
||||
Constants.LOGGER.error("Default config file not found in resources");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Constants.LOGGER.error("Failed to copy default config file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Promise<Void> startPromise) {
|
||||
public void start(Promise<Void> startPromise) {
|
||||
System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
|
||||
init();
|
||||
|
||||
final DeploymentOptions options = new DeploymentOptions();
|
||||
options.setThreadingModel(ThreadingModel.WORKER);
|
||||
|
||||
vertx.deployVerticle(new DataLayerAPIVerticle(), options, result -> {
|
||||
if(result.succeeded()) {
|
||||
Constants.LOGGER.info(String.format(
|
||||
"🟢 DataLayerAPIVerticle desplegado. (http://%s:%d)",
|
||||
configManager.getHost(), configManager.getDataApiPort()
|
||||
));
|
||||
} else {
|
||||
Constants.LOGGER.error("🔴 Error al desplegar DataLayerAPIVerticle", result.cause());
|
||||
}
|
||||
});
|
||||
|
||||
getVertx().deployVerticle(new DataLayerAPIVerticle(), options);
|
||||
getVertx().deployVerticle(new LogicLayerAPIVerticle(), options);
|
||||
getVertx().deployVerticle(new HttpServerVerticle());
|
||||
vertx.deployVerticle(new LogicLayerAPIVerticle(), options, result -> {
|
||||
if(result.succeeded()) {
|
||||
Constants.LOGGER.info(String.format(
|
||||
"🟢 ApiVerticle desplegado. (http://%s:%d)",
|
||||
configManager.getHost(), configManager.getLogicApiPort()
|
||||
));
|
||||
} else {
|
||||
Constants.LOGGER.error("🔴 Error al desplegar LogicApiVerticle", result.cause());
|
||||
}
|
||||
});
|
||||
|
||||
vertx.deployVerticle(new WebServerVerticle(), result -> {
|
||||
if(result.succeeded()) {
|
||||
Constants.LOGGER.info(String.format(
|
||||
"🟢 WebServerVerticle desplegado. (http://%s:%d)",
|
||||
configManager.getHost(), configManager.getWebserverPort()));
|
||||
} else {
|
||||
Constants.LOGGER.error("🔴 Error al desplegar WebServerVerticle", result.cause());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.miarma.contaminus.server;
|
||||
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.ext.web.Router;
|
||||
import io.vertx.ext.web.handler.StaticHandler;
|
||||
import net.miarma.contaminus.common.ConfigManager;
|
||||
import net.miarma.contaminus.common.Constants;
|
||||
|
||||
public class WebServerVerticle extends AbstractVerticle {
|
||||
private final ConfigManager configManager = ConfigManager.getInstance();
|
||||
|
||||
@Override
|
||||
public void start(Promise<Void> startPromise) {
|
||||
Constants.LOGGER.info("📡 Iniciando WebServerVerticle...");
|
||||
|
||||
Router router = Router.router(vertx);
|
||||
|
||||
router.route("/*")
|
||||
.handler(
|
||||
StaticHandler.create("webroot")
|
||||
.setDefaultContentEncoding("UTF-8")
|
||||
);
|
||||
|
||||
router.route("/dashboard/*").handler(ctx -> {
|
||||
ctx.reroute("/index.html");
|
||||
});
|
||||
|
||||
vertx.createHttpServer()
|
||||
.requestHandler(router)
|
||||
.listen(configManager.getWebserverPort(), configManager.getHost());
|
||||
|
||||
startPromise.complete();
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package net.miarma.contaminus.util;
|
||||
|
||||
import net.miarma.contaminus.common.ConfigManager;
|
||||
import net.miarma.contaminus.common.OSType;
|
||||
|
||||
public class SystemUtil {
|
||||
private static ConfigManager configManager;
|
||||
|
||||
private static String host;
|
||||
private static int dataApiPort;
|
||||
private static int logicApiPort;
|
||||
private static int webserverPort;
|
||||
|
||||
public static void init() {
|
||||
configManager = ConfigManager.getInstance();
|
||||
|
||||
host = configManager.getStringProperty("inet.host");
|
||||
dataApiPort = configManager.getIntProperty("data-api.port");
|
||||
logicApiPort = configManager.getIntProperty("logic-api.port");
|
||||
webserverPort = configManager.getIntProperty("web.port");
|
||||
}
|
||||
|
||||
public static String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public static int getDataApiPort() {
|
||||
return dataApiPort;
|
||||
}
|
||||
|
||||
public static int getLogicApiPort() {
|
||||
return logicApiPort;
|
||||
}
|
||||
|
||||
public static int getWebserverPort() {
|
||||
return webserverPort;
|
||||
}
|
||||
|
||||
public static OSType getOS() {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
if (os.contains("win")) {
|
||||
return OSType.WINDOWS;
|
||||
} else if (os.contains("nix") || os.contains("nux")) {
|
||||
return OSType.LINUX;
|
||||
} else {
|
||||
return OSType.INVALID_OS;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user