|
| 1 | +package io.nodelink.server.app.node.api; |
| 2 | + |
| 3 | +import io.javalin.Javalin; |
| 4 | +import io.nodelink.server.NodeLink; |
| 5 | +import io.nodelink.server.app.config.RouteHandler; |
| 6 | +import org.slf4j.LoggerFactory; |
| 7 | +import ch.qos.logback.classic.Level; |
| 8 | +import ch.qos.logback.classic.LoggerContext; |
| 9 | +import reactor.core.publisher.Mono; |
| 10 | +import reactor.core.scheduler.Schedulers; |
| 11 | + |
| 12 | +public class NodeStarter { |
| 13 | + |
| 14 | + private static final NodeStarter INSTANCE = new NodeStarter(); |
| 15 | + private Javalin app; |
| 16 | + |
| 17 | + static { |
| 18 | + LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); |
| 19 | + loggerContext.getLogger("io.javalin").setLevel(Level.OFF); |
| 20 | + loggerContext.getLogger("org.eclipse.jetty").setLevel(Level.OFF); |
| 21 | + loggerContext.getLogger("reactor").setLevel(Level.OFF); |
| 22 | + } |
| 23 | + |
| 24 | + public void startServer() { |
| 25 | + Mono.fromRunnable(() -> { |
| 26 | + app = Javalin.create(config -> { |
| 27 | + config.showJavalinBanner = false; |
| 28 | + config.router.contextPath = "/bone"; |
| 29 | + }).start(8080); |
| 30 | + |
| 31 | + RouteHandler.registerAllRoutes(app, "io.nodelink.server.app.node.api.routes"); |
| 32 | + |
| 33 | + NodeLink.getInstance().getLogger().SUCCESS("Node API Server started"); |
| 34 | + }) |
| 35 | + .subscribeOn(Schedulers.boundedElastic()) |
| 36 | + .subscribe(); |
| 37 | + } |
| 38 | + |
| 39 | + public Javalin getApp() { |
| 40 | + return app; |
| 41 | + } |
| 42 | + |
| 43 | + public static NodeStarter getNodeStarterSingleton() { |
| 44 | + return INSTANCE; |
| 45 | + } |
| 46 | +} |
0 commit comments