package tech.greenfield.vertx.irked.example;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.core.http.HttpServerOptions;
import tech.greenfield.vertx.irked.Controller;
import tech.greenfield.vertx.irked.Irked;
import tech.greenfield.vertx.irked.annotations.Endpoint;
import tech.greenfield.vertx.irked.helpers.Redirect;

public class App extends AbstractVerticle {

	@Override
	public void start(Promise<Void> startFuture) throws Exception {
		vertx.createHttpServer(new HttpServerOptions())
				.requestHandler(Irked.irked(vertx).router()
						.configure(new ExampleAPIv1(), "/v1")
						.configure(new ExampleAPIv2(), "/v2")
						.configure(new Controller() {
							@Endpoint("/")
							WebHandler latest = r -> {
								throw new Redirect("/v2" + r.request().uri()).unchecked();
							};
						}))
				.listen(config().getInteger("port", 8080))
				.onSuccess(v -> startFuture.complete())
				.onFailure(t -> startFuture.fail(t));
	}

}

@@ -281,28 +281,127 @@
 ked.
-annotations.Endpoint
+Request;%0Aimport tech.greenfield.vertx.irked.annotations.Endpoint;%0Aimport tech.greenfield.vertx.irked.annotations.OnFail
 ;%0Aim
@@ -573,16 +573,123 @@
 ption %7B%0A
+%09%09System.out.println(%22Starting Irked example app listening on port %22 + config().getInteger(%22port%22, 8000));%0A
 %09%09vertx.
@@ -1035,16 +1035,115 @@
 %09%09%09%09%09%7D;%0A
+%09%09%09%09%09%09%09@OnFail%0A%09%09%09%09%09%09%09@Endpoint(%22/*%22)%0A%09%09%09%09%09%09%09WebHandler failureHandler = Request.failureHandler();%0A
 %09%09%09%09%09%09%7D)
@@ -1186,17 +1186,17 @@
 ort%22, 80
-8
+0
 0))%0A%09%09%09%09

add a failure handle so that redirect works