Skip to content

Commit

Permalink
Added option to change the RestAPI server port
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCGuyGitHub committed Jun 30, 2024
1 parent f28a222 commit 30e0b24
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import jakarta.inject.Named
import jakarta.inject.Singleton
import kong.unirest.core.json.JSONArray
import kong.unirest.core.json.JSONObject
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.jetbrains.annotations.NotNull
Expand All @@ -42,21 +43,6 @@ class CloudNet_Rest_Module : DriverModule() {






@ModuleTask(lifecycle = ModuleLifeCycle.STARTED)
fun started(
@NotNull cloudServiceManager: CloudServiceManager,
@NotNull shutdownHandler: ShutdownHandler,
@NotNull @Named("module") injectionLayer: InjectionLayer<*>
) {
logger.info("Listening on port 8080!")
GlobalScope.launch {
main(cloudServiceManager, shutdownHandler)
}
}

@ModuleTask(order = 127, lifecycle = ModuleLifeCycle.LOADED)
fun load() {
val config = this.readConfig(DocumentFactory.json())
Expand All @@ -67,7 +53,8 @@ class CloudNet_Rest_Module : DriverModule() {
config.getString("password"),
config.getString("database"),
config.getString("host"),
config.getInt("port")
config.getInt("port"),
config.getInt("restapi_port")
)
)
)
Expand All @@ -82,12 +69,16 @@ class CloudNet_Rest_Module : DriverModule() {
"123456",
"cloudnet_rest",
"127.0.0.1",
3306
3306,
8080
)
},
DocumentFactory.json()
)




val config = HikariConfig()

config.jdbcUrl = "jdbc:mysql://${configuration!!.host}:${configuration!!.port}/${configuration!!.database}"
Expand All @@ -114,6 +105,18 @@ class CloudNet_Rest_Module : DriverModule() {
ds.close()
}

@ModuleTask(order = 127, lifecycle = ModuleLifeCycle.STARTED)
fun started(
@NotNull cloudServiceManager: CloudServiceManager,
@NotNull shutdownHandler: ShutdownHandler,
@NotNull @Named("module") injectionLayer: InjectionLayer<*>
) {
GlobalScope.launch {
main(cloudServiceManager, shutdownHandler)
}
logger.info("Rest API listening on port ${configuration!!.restapi_port.toString()}!")
}

@ModuleTask(lifecycle = ModuleLifeCycle.STARTED)
fun start(commandProvider: CommandProvider) {
commandProvider.register(Test::class.java)
Expand Down Expand Up @@ -145,7 +148,8 @@ class CloudNet_Rest_Module : DriverModule() {
@NotNull cloudServiceManager: CloudServiceManager,
@NotNull shutdownHandler: ShutdownHandler
) {
embeddedServer(Netty, port = 8080) {
val port = configuration!!.restapi_port
embeddedServer(Netty, port = port) {

install(ShutDownUrl.ApplicationCallPlugin) {
shutDownUrl = "/debug/shutdown"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ class Configuration(
@NotNull val password: String,
@NotNull val database: String,
@NotNull val host: String,
@NotNull val port: Int
@NotNull val port: Int,
@NotNull val restapi_port: Int
)

0 comments on commit 30e0b24

Please sign in to comment.