mirror of
https://github.com/revanced/revanced-api.git
synced 2025-04-30 06:34:36 +02:00
feat: Move config file to CLI argument
This commit is contained in:
parent
8614e5eed6
commit
6a9f0cadac
@ -1,5 +1,3 @@
|
|||||||
# File path to store configurations for the API
|
|
||||||
CONFIG_FILE_PATH=configuration.toml
|
|
||||||
# Optional token for API calls to the backend
|
# Optional token for API calls to the backend
|
||||||
BACKEND_API_TOKEN=
|
BACKEND_API_TOKEN=
|
||||||
# A URL to the old API to proxy for migration purposes
|
# A URL to the old API to proxy for migration purposes
|
||||||
|
@ -8,6 +8,7 @@ import app.revanced.api.configuration.routing.configureRouting
|
|||||||
import io.ktor.server.engine.*
|
import io.ktor.server.engine.*
|
||||||
import io.ktor.server.jetty.*
|
import io.ktor.server.jetty.*
|
||||||
import picocli.CommandLine
|
import picocli.CommandLine
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
@CommandLine.Command(
|
@CommandLine.Command(
|
||||||
name = "start",
|
name = "start",
|
||||||
@ -28,9 +29,16 @@ internal object StartAPICommand : Runnable {
|
|||||||
)
|
)
|
||||||
private var port: Int = 8888
|
private var port: Int = 8888
|
||||||
|
|
||||||
|
@CommandLine.Option(
|
||||||
|
names = ["-c", "--config"],
|
||||||
|
description = ["The path to the configuration file."],
|
||||||
|
showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
|
||||||
|
)
|
||||||
|
private var configFile = File("configuration.toml")
|
||||||
|
|
||||||
override fun run() {
|
override fun run() {
|
||||||
embeddedServer(Jetty, port, host) {
|
embeddedServer(Jetty, port, host) {
|
||||||
configureDependencies()
|
configureDependencies(configFile)
|
||||||
configureHTTP(allowedHost = host)
|
configureHTTP(allowedHost = host)
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity()
|
configureSecurity()
|
||||||
|
@ -33,7 +33,9 @@ import org.koin.ktor.plugin.Koin
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@OptIn(ExperimentalSerializationApi::class)
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
fun Application.configureDependencies() {
|
fun Application.configureDependencies(
|
||||||
|
configFile: File,
|
||||||
|
) {
|
||||||
val globalModule = module {
|
val globalModule = module {
|
||||||
single {
|
single {
|
||||||
Dotenv.configure().load()
|
Dotenv.configure().load()
|
||||||
@ -99,11 +101,8 @@ fun Application.configureDependencies() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
single {
|
single<ConfigurationRepository> {
|
||||||
val configFilePath = get<Dotenv>()["CONFIG_FILE_PATH"]
|
Toml.decodeFromStream(configFile.inputStream())
|
||||||
val configFile = File(configFilePath).inputStream()
|
|
||||||
|
|
||||||
Toml.decodeFromStream<ConfigurationRepository>(configFile)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
singleOf(::AnnouncementRepository)
|
singleOf(::AnnouncementRepository)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user