Skip to content

Commit

Permalink
Add config for data index url (apache#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianonicolai authored and mswiderski committed Oct 3, 2019
1 parent 387bc35 commit 55f2af2
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 2 deletions.
4 changes: 4 additions & 0 deletions 04-kogito-travel-agency/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kafka-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-web</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.kie.kogito.app;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import io.quarkus.vertx.web.Route;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpHeaders;
import io.vertx.ext.web.RoutingContext;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import static io.vertx.core.http.HttpMethod.GET;
import static java.nio.charset.StandardCharsets.UTF_8;

@ApplicationScoped
public class VertxRouter {

@Inject
@ConfigProperty(name = "kogito.dataindex.url", defaultValue = "http://localhost:8180/graphql")
private String dataIndexURL;

@Inject
private Vertx vertx;

private String resource;

@PostConstruct
public void init() {
resource = vertx.fileSystem()
.readFileBlocking("META-INF/resources/index.html")
.toString(UTF_8)
.replace("__GRAPHIQL_ENDPOINT__", "\"" + dataIndexURL + "\"");
}

@Route(path = "/", methods = GET)
public void handle(RoutingContext context) {
try {
context.response()
.putHeader(HttpHeaders.CACHE_CONTROL, "no-cache")
.putHeader(HttpHeaders.CONTENT_TYPE, "text/html;charset=utf8")
.end(resource);
} catch (Exception ex) {
ex.printStackTrace();
context.fail(500, ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h1>Travels</h1>
</div>
</div>
<script>
var graphql = "http://localhost:8180/graphql";
var graphql = __GRAPHIQL_ENDPOINT__;

$(function () {
$.ajaxSetup({
Expand Down
4 changes: 4 additions & 0 deletions 04-kogito-visas/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-web</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand Down
48 changes: 48 additions & 0 deletions 04-kogito-visas/src/main/java/org/kie/kogito/app/VertxRouter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.kie.kogito.app;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import io.quarkus.vertx.web.Route;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpHeaders;
import io.vertx.ext.web.RoutingContext;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import static io.vertx.core.http.HttpMethod.GET;
import static java.nio.charset.StandardCharsets.UTF_8;

@ApplicationScoped
public class VertxRouter {

@Inject
@ConfigProperty(name = "kogito.dataindex.url", defaultValue = "http://localhost:8180/graphql")
private String dataIndexURL;

@Inject
private Vertx vertx;

private String resource;

@PostConstruct
public void init() {
resource = vertx.fileSystem()
.readFileBlocking("META-INF/resources/index.html")
.toString(UTF_8)
.replace("__GRAPHIQL_ENDPOINT__", "\"" + dataIndexURL + "\"");
}

@Route(path = "/", methods = GET)
public void handle(RoutingContext context) {
try {
context.response()
.putHeader(HttpHeaders.CACHE_CONTROL, "no-cache")
.putHeader(HttpHeaders.CONTENT_TYPE, "text/html;charset=utf8")
.end(resource);
} catch (Exception ex) {
ex.printStackTrace();
context.fail(500, ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h1>Visa applications</h1>
</div>
</div>
<script>
var graphql = "http://localhost:8180/graphql";
var graphql = __GRAPHIQL_ENDPOINT__;

$(function () {
$.ajaxSetup({
Expand Down

0 comments on commit 55f2af2

Please sign in to comment.