File tree Expand file tree Collapse file tree
main/kotlin/com/sakethh/linkora
test/kotlin/com/sakethh/linkora Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com.sakethh.linkora
22
3+ import com.sakethh.linkora.data.configureDatabase
34import com.sakethh.linkora.domain.model.ServerConfig
5+ import com.sakethh.linkora.presentation.routing.websocket.configureEventsWebSocket
6+ import com.sakethh.linkora.presentation.routing.configureRouting
47import com.sakethh.linkora.utils.SysEnvKey
5- import com.sakethh.linkora.utils.hostedOnRemote
8+ import com.sakethh.linkora.utils.useSysEnvValues
69import io.ktor.server.application.*
710import io.ktor.server.engine.*
811import io.ktor.server.netty.*
@@ -75,12 +78,13 @@ object ServerConfiguration {
7578 }
7679
7780 fun readConfig (): ServerConfig {
78- return if (hostedOnRemote ()) {
81+ return if (useSysEnvValues ()) {
7982 ServerConfig (
8083 databaseUrl = " jdbc:" + System .getenv(SysEnvKey .LINKORA_DATABASE_URL .name),
8184 databaseUser = System .getenv(SysEnvKey .LINKORA_DATABASE_USER .name),
8285 databasePassword = System .getenv(SysEnvKey .LINKORA_DATABASE_PASSWORD .name), hostAddress = try {
83- System .getenv(SysEnvKey .LINKORA_HOST_ADDRESS .name)
86+ // manually throw the exception as `getenv` may return null, and no conversion is happening here to auto-throw
87+ System .getenv(SysEnvKey .LINKORA_HOST_ADDRESS .name) ? : throw NullPointerException ()
8488 } catch (_: Exception ) {
8589 " 0.0.0.0"
8690 }, serverPort = try {
Original file line number Diff line number Diff line change 1- package com.sakethh.linkora
1+ package com.sakethh.linkora.data
22
3+ import com.sakethh.linkora.ServerConfiguration
34import com.sakethh.linkora.domain.model.ServerConfig
45import com.sakethh.linkora.domain.tables.*
5- import com.sakethh.linkora.utils.hostedOnRemote
6+ import com.sakethh.linkora.utils.useSysEnvValues
67import org.jetbrains.exposed.sql.Database
78import org.jetbrains.exposed.sql.SchemaUtils
89import org.jetbrains.exposed.sql.transactions.transaction
@@ -54,7 +55,7 @@ fun configureDatabase() {
5455 }
5556 } else if (e.message?.contains(" Database driver not found for" ) == true || e.message?.contains(" Access denied" ) == true ) {
5657 println (e.message)
57- if (hostedOnRemote ()) {
58+ if (useSysEnvValues ()) {
5859 println (" \n Manually causing the crash since the correct values aren't provided through environment variables." )
5960 throw e
6061 }
Original file line number Diff line number Diff line change 1- package com.sakethh.linkora
1+ package com.sakethh.linkora.data.socket.manager
22
33import com.sakethh.linkora.domain.model.WebSocketEvent
44import io.ktor.server.websocket.*
Original file line number Diff line number Diff line change 1- package com.sakethh.linkora
1+ package com.sakethh.linkora.presentation.routing
22
3+ import com.sakethh.linkora.Security
34import com.sakethh.linkora.data.repository.FoldersImplementation
45import com.sakethh.linkora.data.repository.LinksImplementation
56import com.sakethh.linkora.data.repository.PanelsRepoImpl
@@ -9,10 +10,10 @@ import com.sakethh.linkora.domain.repository.LinksRepository
910import com.sakethh.linkora.domain.repository.PanelsRepository
1011import com.sakethh.linkora.domain.repository.SyncRepo
1112import com.sakethh.linkora.domain.routes.SyncRoute
12- import com.sakethh.linkora.routing.foldersRouting
13- import com.sakethh.linkora.routing.linksRouting
14- import com.sakethh.linkora.routing.panelsRouting
15- import com.sakethh.linkora.routing.syncRouting
13+ import com.sakethh.linkora.presentation. routing.http .foldersRouting
14+ import com.sakethh.linkora.presentation. routing.http .linksRouting
15+ import com.sakethh.linkora.presentation. routing.http .panelsRouting
16+ import com.sakethh.linkora.presentation. routing.http .syncRouting
1617import io.ktor.http.*
1718import io.ktor.server.application.*
1819import io.ktor.server.auth.*
Original file line number Diff line number Diff line change 1- package com.sakethh.linkora.routing
1+ package com.sakethh.linkora.presentation. routing.http
22
33import com.sakethh.linkora.Security
44import com.sakethh.linkora.domain.dto.IDBasedDTO
Original file line number Diff line number Diff line change 1- package com.sakethh.linkora.routing
1+ package com.sakethh.linkora.presentation. routing.http
22
33import com.sakethh.linkora.Security
4- import com.sakethh.linkora.domain.Link
54import com.sakethh.linkora.domain.dto.IDBasedDTO
65import com.sakethh.linkora.domain.dto.link.*
76import com.sakethh.linkora.domain.repository.LinksRepository
Original file line number Diff line number Diff line change 1- package com.sakethh.linkora.routing
1+ package com.sakethh.linkora.presentation. routing.http
22
33import com.sakethh.linkora.Security
44import com.sakethh.linkora.domain.dto.IDBasedDTO
Original file line number Diff line number Diff line change 1- package com.sakethh.linkora.routing
1+ package com.sakethh.linkora.presentation. routing.http
22
33import com.sakethh.linkora.Security
44import com.sakethh.linkora.domain.repository.SyncRepo
Original file line number Diff line number Diff line change 1- package com.sakethh.linkora
1+ package com.sakethh.linkora.presentation.routing.websocket
22
3- import com.sakethh.linkora.EventsWebSocketManager.closeWriteChannel
4- import com.sakethh.linkora.EventsWebSocketManager.initializeWriteChannel
3+ import com.sakethh.linkora.data.socket.manager.EventsWebSocketManager.closeWriteChannel
4+ import com.sakethh.linkora.data.socket.manager.EventsWebSocketManager.initializeWriteChannel
5+ import com.sakethh.linkora.Security
56import com.sakethh.linkora.domain.dto.Correlation
67import io.ktor.server.application.*
78import io.ktor.server.auth.*
Original file line number Diff line number Diff line change 11package com.sakethh.linkora.utils
22
3- fun hostedOnRemote (): Boolean {
3+ fun useSysEnvValues (): Boolean {
44 return try {
55 System .getenv(SysEnvKey .LINKORA_SERVER_USE_ENV_VAL .name).toBooleanStrict()
66 } catch (e: Exception ) {
You can’t perform that action at this time.
0 commit comments