commit 8eee21b9c30c02e16049115b36bd690fb797e87e Author: Colin McDonald Date: Fri Feb 5 18:09:59 2016 -0500 Initial commit! diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a8af657 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# Eclipse +.classpath +.project +.settings/ + +# Intellij +.idea/ +*.iml +*.iws + +# Mac +.DS_Store + +# Maven +log/ +target/ +dependency-reduced-pom.xml + +*.jar \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7189b12 --- /dev/null +++ b/pom.xml @@ -0,0 +1,76 @@ + + 4.0.0 + net.frozenorb + APIv3 + 1.0 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.2 + + 1.8 + 1.8 + UTF-8 + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + + + *:* + + + + + + package + + shade + + + + + + + + src/main/resources + true + + + + + + + io.vertx + vertx-core + 3.2.0 + + + io.vertx + vertx-web + 3.2.0 + + + io.vertx + vertx-mongo-client + 3.2.0 + + + io.vertx + vertx-redis-client + 3.2.0 + + + org.projectlombok + lombok + LATEST + + + \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java new file mode 100644 index 0000000..de406c2 --- /dev/null +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -0,0 +1,52 @@ +package net.frozenorb.apiv3; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.Vertx; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.ext.mongo.MongoClient; +import io.vertx.ext.web.Router; + +import java.util.List; + +public class APIv3 extends AbstractVerticle { + + public static void main(String[] args) { + Vertx.vertx().deployVerticle(new APIv3()); + } + + public void start() { + Router coreHttpRouter = Router.router(vertx); + MongoClient mongo = MongoClient.createShared(vertx, new JsonObject() + .put("host", "ds055505.mongolab.com") + .put("port", 55505) + .put("username", "test") + .put("password", "test") + .put("db_name", "minehqapi") + ); + + coreHttpRouter.route("/*").handler(ctx -> { + ctx.response().putHeader("content-type", "application/json"); + ctx.next(); + }); + + coreHttpRouter.get("/servers").handler(ctx -> { + long start = System.currentTimeMillis(); + mongo.find("servers", new JsonObject(), result -> { + if (result.succeeded()) { + if (true) { + ctx.response().end("{'time': " + (System.currentTimeMillis() - start) + "}"); + return; + } + List servers = result.result(); + ctx.response().end(new JsonArray(servers).encode()); + } else { + result.cause().printStackTrace(); + } + }); + }); + + vertx.createHttpServer().requestHandler(coreHttpRouter::accept).listen(80); + } + +} \ No newline at end of file