mirror of
https://github.com/revanced/revanced-api.git
synced 2025-04-29 22:24:31 +02:00
fix: Configure CORS correctly
This commit is contained in:
parent
a7666ba29d
commit
2ed4cf3b40
@ -10,5 +10,8 @@ contributors-repositories = [
|
|||||||
"revanced-manager",
|
"revanced-manager",
|
||||||
]
|
]
|
||||||
api-version = 1
|
api-version = 1
|
||||||
cors = { host = "*.revanced.app", sub-domains = [] }
|
cors-allowed-hosts = [
|
||||||
|
"revanced.app",
|
||||||
|
"*.revanced.app"
|
||||||
|
]
|
||||||
endpoint = "https://api.revanced.app"
|
endpoint = "https://api.revanced.app"
|
@ -13,11 +13,13 @@ fun Application.configureHTTP() {
|
|||||||
val configurationRepository = get<ConfigurationRepository>()
|
val configurationRepository = get<ConfigurationRepository>()
|
||||||
|
|
||||||
install(CORS) {
|
install(CORS) {
|
||||||
|
configurationRepository.corsAllowedHosts.forEach { host ->
|
||||||
allowHost(
|
allowHost(
|
||||||
host = configurationRepository.cors.host,
|
host = host,
|
||||||
subDomains = configurationRepository.cors.subDomains,
|
schemes = listOf("http", "https")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
install(RateLimit) {
|
install(RateLimit) {
|
||||||
fun rateLimit(name: String, block: RateLimitProviderConfig.() -> Unit) = register(RateLimitName(name)) {
|
fun rateLimit(name: String, block: RateLimitProviderConfig.() -> Unit) = register(RateLimitName(name)) {
|
||||||
|
@ -19,7 +19,7 @@ import java.io.File
|
|||||||
* @property integrations The source of the integrations.
|
* @property integrations The source of the integrations.
|
||||||
* @property contributorsRepositoryNames The names of the repositories to get contributors from.
|
* @property contributorsRepositoryNames The names of the repositories to get contributors from.
|
||||||
* @property apiVersion The version to use for the API.
|
* @property apiVersion The version to use for the API.
|
||||||
* @property cors The CORS configuration.
|
* @property corsAllowedHosts The hosts allowed to make requests to the API.
|
||||||
* @property endpoint The endpoint of the API.
|
* @property endpoint The endpoint of the API.
|
||||||
*/
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
@ -31,7 +31,8 @@ internal class ConfigurationRepository(
|
|||||||
val contributorsRepositoryNames: Set<String>,
|
val contributorsRepositoryNames: Set<String>,
|
||||||
@SerialName("api-version")
|
@SerialName("api-version")
|
||||||
val apiVersion: Int = 1,
|
val apiVersion: Int = 1,
|
||||||
val cors: Cors,
|
@SerialName("cors-allowed-hosts")
|
||||||
|
val corsAllowedHosts: Set<String>,
|
||||||
val endpoint: String,
|
val endpoint: String,
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
@ -61,19 +62,6 @@ internal class ConfigurationRepository(
|
|||||||
@SerialName("public-key-file")
|
@SerialName("public-key-file")
|
||||||
val publicKeyFile: File,
|
val publicKeyFile: File,
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
|
||||||
* The CORS configuration.
|
|
||||||
*
|
|
||||||
* @property host The host of the API to configure CORS.
|
|
||||||
* @property subDomains The subdomains to allow for CORS.
|
|
||||||
*/
|
|
||||||
@Serializable
|
|
||||||
internal class Cors(
|
|
||||||
val host: String,
|
|
||||||
@SerialName("sub-domains")
|
|
||||||
val subDomains: List<String>,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private object RegexSerializer : KSerializer<Regex> {
|
private object RegexSerializer : KSerializer<Regex> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user