Initial commit!
This commit is contained in:
commit
8eee21b9c3
19
.gitignore
vendored
Normal file
19
.gitignore
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# Eclipse
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
|
||||
# Intellij
|
||||
.idea/
|
||||
*.iml
|
||||
*.iws
|
||||
|
||||
# Mac
|
||||
.DS_Store
|
||||
|
||||
# Maven
|
||||
log/
|
||||
target/
|
||||
dependency-reduced-pom.xml
|
||||
|
||||
*.jar
|
76
pom.xml
Normal file
76
pom.xml
Normal file
@ -0,0 +1,76 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.frozenorb</groupId>
|
||||
<artifactId>APIv3</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.2</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>*:*</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-core</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-web</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-mongo-client</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-redis-client</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
52
src/main/java/net/frozenorb/apiv3/APIv3.java
Normal file
52
src/main/java/net/frozenorb/apiv3/APIv3.java
Normal file
@ -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<JsonObject> servers = result.result();
|
||||
ctx.response().end(new JsonArray(servers).encode());
|
||||
} else {
|
||||
result.cause().printStackTrace();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
vertx.createHttpServer().requestHandler(coreHttpRouter::accept).listen(80);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user