diff --git a/ruoyi-gateway/pom.xml b/ruoyi-gateway/pom.xml index 771df7fd0..d698c0feb 100644 --- a/ruoyi-gateway/pom.xml +++ b/ruoyi-gateway/pom.xml @@ -1,110 +1,198 @@ - - - com.ruoyi - ruoyi - 3.6.4 - - 4.0.0 - - ruoyi-gateway - - - ruoyi-gateway网关模块 - - - - - - - org.springframework.cloud - spring-cloud-starter-gateway - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-config - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-sentinel - - - - - com.alibaba.cloud - spring-cloud-alibaba-sentinel-gateway - - - - - com.alibaba.csp - sentinel-datasource-nacos - - - - - org.springframework.boot - spring-boot-starter-actuator - - - - - org.springframework.cloud - spring-cloud-loadbalancer - - - - - pro.fessional - kaptcha - - - - - com.ruoyi - ruoyi-common-redis - - - - - io.springfox - springfox-swagger-ui - ${swagger.fox.version} - - - io.springfox - springfox-swagger2 - ${swagger.fox.version} - - - - - - ${project.artifactId} - - - org.springframework.boot - spring-boot-maven-plugin - - - - repackage - - - - - - - - + + + com.ruoyi + ruoyi + 3.6.4 + + 4.0.0 + + ruoyi-gateway + + + ruoyi-gateway网关模块 + + + + 2.0.0 + + + + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + com.alibaba.cloud + spring-cloud-alibaba-sentinel-gateway + + + + + com.alibaba.csp + sentinel-datasource-nacos + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + org.springframework.cloud + spring-cloud-loadbalancer + + + + + pro.fessional + kaptcha + + + + + com.ruoyi + ruoyi-common-redis + + + + + io.springfox + springfox-swagger-ui + ${swagger.fox.version} + + + io.springfox + springfox-swagger2 + ${swagger.fox.version} + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-test + ${kotlin.version} + test + + + + + + ${project.artifactId} + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + add-source + generate-sources + + add-source + + + + src/main/java + src/main/kotlin + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + 1.8 + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + none + + + default-testCompile + none + + + compile + compile + + compile + + + + testCompile + test-compile + + testCompile + + + + + + + + diff --git a/ruoyi-gateway/src/main/kotlin/com/ruoyi/gateway/config/CorsFilter.kt b/ruoyi-gateway/src/main/kotlin/com/ruoyi/gateway/config/CorsFilter.kt new file mode 100644 index 000000000..aa4a04712 --- /dev/null +++ b/ruoyi-gateway/src/main/kotlin/com/ruoyi/gateway/config/CorsFilter.kt @@ -0,0 +1,32 @@ +package com.ruoyi.gateway.config + +import org.apache.commons.lang3.ObjectUtils +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.web.server.WebFilter + + +@Configuration +open class CorsConfig { + @Value("\${cors.orgins}") + private val corsOrgins: String? = null + + @Bean + open fun corsFilter(): WebFilter { + return WebFilter { exchange, chain -> + val response = exchange.response + val request = exchange.request + if (!ObjectUtils.isEmpty(corsOrgins)) { + response.headers["Access-Control-Allow-Origin"] = corsOrgins + } else { + response.headers["Access-Control-Allow-Origin"] = "*" + } + response.headers["Access-Control-Allow-Credentials"] = "true" + response.headers["Access-Control-Max-Age"] = "3600" + response.headers["Access-Control-Allow-Methods"] = "GET,POST,PUT,DELETE,OPTIONS,HEAD" + response.headers["Access-Control-Allow-Headers"] = "X-Requested-With, Content-Type, Authorization, credential, X-XSRF-TOKEN, token, Admin-Token, App-Token" + chain.filter(exchange.mutate().request(request.mutate().build()).build()) + } + } +} \ No newline at end of file