mirror of
https://github.com/revanced/revanced-api.git
synced 2025-04-29 22:24:31 +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
|
||||
BACKEND_API_TOKEN=
|
||||
# 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.jetty.*
|
||||
import picocli.CommandLine
|
||||
import java.io.File
|
||||
|
||||
@CommandLine.Command(
|
||||
name = "start",
|
||||
@ -28,9 +29,16 @@ internal object StartAPICommand : Runnable {
|
||||
)
|
||||
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() {
|
||||
embeddedServer(Jetty, port, host) {
|
||||
configureDependencies()
|
||||
configureDependencies(configFile)
|
||||
configureHTTP(allowedHost = host)
|
||||
configureSerialization()
|
||||
configureSecurity()
|
||||
|
@ -33,7 +33,9 @@ import org.koin.ktor.plugin.Koin
|
||||
import java.io.File
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
fun Application.configureDependencies() {
|
||||
fun Application.configureDependencies(
|
||||
configFile: File,
|
||||
) {
|
||||
val globalModule = module {
|
||||
single {
|
||||
Dotenv.configure().load()
|
||||
@ -99,11 +101,8 @@ fun Application.configureDependencies() {
|
||||
)
|
||||
}
|
||||
|
||||
single {
|
||||
val configFilePath = get<Dotenv>()["CONFIG_FILE_PATH"]
|
||||
val configFile = File(configFilePath).inputStream()
|
||||
|
||||
Toml.decodeFromStream<ConfigurationRepository>(configFile)
|
||||
single<ConfigurationRepository> {
|
||||
Toml.decodeFromStream(configFile.inputStream())
|
||||
}
|
||||
|
||||
singleOf(::AnnouncementRepository)
|
||||
|
Loading…
x
Reference in New Issue
Block a user