api changes cors
This commit is contained in:
@@ -8,7 +8,8 @@ public class Constants {
|
||||
public static final String API_PREFIX = "/api/v1";
|
||||
public static final String HOME_DIR = SystemInfo.getOS() == OSType.WINDOWS ?
|
||||
"C:/Users/" + System.getProperty("user.name") + "/" :
|
||||
System.getProperty("user.home") + "/";
|
||||
System.getProperty("user.home").contains("root") ? "/root/" :
|
||||
"/home/" + System.getProperty("user.name") + "/";
|
||||
public static final String BASE_DIR = HOME_DIR +
|
||||
(SystemInfo.getOS() == OSType.WINDOWS ? ".contaminus" :
|
||||
SystemInfo.getOS() == OSType.LINUX ? ".config" + "/" +
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package net.miarma.contaminus.common;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class Host {
|
||||
static ConfigManager configManager = ConfigManager.getInstance();
|
||||
static String host = configManager.getStringProperty("inet.host");
|
||||
static String origin = configManager.getStringProperty("inet.origin");
|
||||
static int apiPort = configManager.getIntProperty("api.port");
|
||||
static int webserverPort = configManager.getIntProperty("webserver.port");
|
||||
|
||||
@@ -18,8 +21,10 @@ public class Host {
|
||||
return webserverPort;
|
||||
}
|
||||
|
||||
public static String getOrigin() {
|
||||
return "http://" + host + ":" + webserverPort;
|
||||
public static Set<String> getOrigins() {
|
||||
return Set.of("http://" + origin + ":" + webserverPort,
|
||||
"https://" + origin + ":" + webserverPort);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,11 +25,12 @@ public class ApiVerticle extends AbstractVerticle {
|
||||
Constants.LOGGER.info("🟢 Iniciando ApiVerticle...");
|
||||
Router router = Router.router(vertx);
|
||||
|
||||
Set<HttpMethod> allowedMethods = new HashSet<>(Arrays.asList(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT)); // Por ejemplo
|
||||
Set<HttpMethod> allowedMethods = new HashSet<>(
|
||||
Arrays.asList(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.OPTIONS)); // Por ejemplo
|
||||
Set<String> allowedHeaders = new HashSet<>(Arrays.asList("Content-Type", "Authorization"));
|
||||
|
||||
router.route().handler(CorsHandler.create()
|
||||
.addOrigin(Host.getOrigin())
|
||||
.addOrigin("*")
|
||||
.allowCredentials(true)
|
||||
.allowedHeaders(allowedHeaders)
|
||||
.allowedMethods(allowedMethods));
|
||||
|
||||
@@ -11,6 +11,7 @@ public class HttpServerVerticle extends AbstractVerticle {
|
||||
@Override
|
||||
public void start() {
|
||||
Constants.LOGGER.info("🟢 Iniciando HttpServerVerticle...");
|
||||
|
||||
Router router = Router.router(vertx);
|
||||
|
||||
router.route("/*").handler(StaticHandler.create(Constants.BASE_DIR + "/webroot")
|
||||
|
||||
@@ -12,10 +12,18 @@ public class MainVerticle extends AbstractVerticle {
|
||||
final DeploymentOptions options = new DeploymentOptions();
|
||||
options.setThreadingModel(ThreadingModel.WORKER);
|
||||
|
||||
String enabledVerticles = System.getProperty("vertx.options", "");
|
||||
|
||||
if (enabledVerticles.contains("db")) {
|
||||
getVertx().deployVerticle(new DatabaseVerticle(), options);
|
||||
}
|
||||
if (enabledVerticles.contains("api")) {
|
||||
getVertx().deployVerticle(new ApiVerticle(), options);
|
||||
}
|
||||
if (enabledVerticles.contains("http")) {
|
||||
getVertx().deployVerticle(new HttpServerVerticle());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Promise<Void> stopPromise) throws Exception {
|
||||
@@ -24,6 +32,7 @@ public class MainVerticle extends AbstractVerticle {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("vertx.options", String.join(",", args));
|
||||
io.vertx.core.Launcher.executeCommand("run", MainVerticle.class.getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -9,5 +9,6 @@ dp.poolSize=5
|
||||
|
||||
# Server Configuration
|
||||
inet.host=localhost
|
||||
inet.origin=localhost
|
||||
webserver.port=8080
|
||||
api.port=8081
|
||||
|
||||
Reference in New Issue
Block a user