Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
082de629
Commit
082de629
authored
Feb 05, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决跨域问题
parent
c080bd96
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
4 deletions
+44
-4
pom.xml
+5
-0
src/main/java/cn/meteor/beyondclouds/config/WebMvcConfig.java
+10
-4
src/main/java/cn/meteor/beyondclouds/core/aop/CorsPreFlightRequestDetector.java
+29
-0
No files found.
pom.xml
View file @
082de629
...
@@ -123,6 +123,11 @@
...
@@ -123,6 +123,11 @@
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
<exclusions>
<exclusions>
...
...
src/main/java/cn/meteor/beyondclouds/config/WebMvcConfig.java
View file @
082de629
...
@@ -6,10 +6,7 @@ import cn.meteor.beyondclouds.core.resolver.CurrentSubjectResolver;
...
@@ -6,10 +6,7 @@ import cn.meteor.beyondclouds.core.resolver.CurrentSubjectResolver;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.*
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
java.util.List
;
import
java.util.List
;
...
@@ -56,4 +53,13 @@ public class WebMvcConfig implements WebMvcConfigurer {
...
@@ -56,4 +53,13 @@ public class WebMvcConfig implements WebMvcConfigurer {
resolvers
.
add
(
new
CurrentSubjectResolver
());
resolvers
.
add
(
new
CurrentSubjectResolver
());
}
}
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
"/**"
)
.
allowedOrigins
(
"*"
)
.
allowedMethods
(
"*"
)
.
allowCredentials
(
true
)
.
maxAge
(
3600
)
.
allowedHeaders
(
"*"
);
}
}
}
src/main/java/cn/meteor/beyondclouds/core/aop/CorsPreFlightRequestDetector.java
0 → 100644
View file @
082de629
package
cn
.
meteor
.
beyondclouds
.
core
.
aop
;
import
lombok.extern.slf4j.Slf4j
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.cors.CorsUtils
;
import
javax.servlet.http.HttpServletRequest
;
/**
* @author meteor
*/
@Aspect
@Component
@Slf4j
public
class
CorsPreFlightRequestDetector
{
@Around
(
value
=
"execution(boolean *..*.preHandle(..))"
)
public
Object
processTx
(
ProceedingJoinPoint
jp
)
throws
Throwable
{
HttpServletRequest
request
=
(
HttpServletRequest
)
jp
.
getArgs
()[
0
];
if
(
request
!=
null
&&
CorsUtils
.
isPreFlightRequest
(
request
))
{
log
.
info
(
"detected pre-flight-request:{}."
,
request
.
getRequestURL
().
toString
());
return
true
;
}
else
{
return
jp
.
proceed
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment