Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
smalltools
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
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
王家辉
smalltools
Commits
a91c2aeb
Commit
a91c2aeb
authored
Feb 18, 2019
by
王家辉
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加对前端的支持
parent
49ab5823
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
1 deletions
+96
-1
src/main/java/com/freemud/config/CorsConfig.java
+67
-0
src/main/java/com/freemud/config/PortalTomcatWebServerCustomizer.java
+27
-0
src/main/resources/application.properties
+2
-1
No files found.
src/main/java/com/freemud/config/CorsConfig.java
0 → 100644
View file @
a91c2aeb
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: CorsConfig
* @Package com.freemud.config
* @Description: 简单描述下这个类是做什么用的
* @author: jiahui.wang
* @date: 2019/2/15 18:18
* @version V1.0
* @Copyright: 2019 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目的
*/
package
com
.
freemud
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
javax.servlet.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
@Component
public
class
CorsConfig
implements
Filter
{
@Override
public
void
doFilter
(
ServletRequest
req
,
ServletResponse
res
,
FilterChain
chain
)
throws
ServletException
{
HttpServletResponse
response
=
(
HttpServletResponse
)
res
;
HttpServletRequest
reqs
=
(
HttpServletRequest
)
req
;
response
.
setHeader
(
"Access-Control-Allow-Origin"
,
"*"
);
response
.
setHeader
(
"Access-Control-Allow-Credentials"
,
"true"
);
response
.
setHeader
(
"Access-Control-Allow-Methods"
,
"GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE"
);
response
.
setHeader
(
"Access-Control-Max-Age"
,
"3600"
);
try
{
if
(
reqs
.
getMethod
().
equals
(
"OPTIONS"
))
{
response
.
setStatus
(
HttpStatus
.
OK
.
value
());
response
.
getWriter
().
write
(
"OPTIONS returns OK"
);
return
;
}
// Filter 只是链式处理,请求依然转发到目的地址。
chain
.
doFilter
(
req
,
response
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
@Override
public
void
init
(
FilterConfig
filterConfig
)
{}
@Override
public
void
destroy
()
{}
@Bean
public
WebMvcConfigurer
webMvcConfigurer
()
{
return
new
WebMvcConfigurerAdapter
()
{
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
"/**"
).
allowedOrigins
(
"*"
);
}
};
}
}
src/main/java/com/freemud/config/PortalTomcatWebServerCustomizer.java
0 → 100644
View file @
a91c2aeb
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: PortalTomcatWebServerCustomizer
* @Package com.freemud.config
* @Description: 防止出现 characters are defined in RFC 7230 and RFC 3986 异常
* @author: jiahui.wang
* @date: 2019/2/15 14:12
* @version V1.0
* @Copyright: 2019 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目的
*/
package
com
.
freemud
.
config
;
import
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
;
import
org.springframework.boot.web.server.WebServerFactoryCustomizer
;
import
org.springframework.stereotype.Component
;
@Component
public
class
PortalTomcatWebServerCustomizer
implements
WebServerFactoryCustomizer
<
TomcatServletWebServerFactory
>
{
@Override
public
void
customize
(
TomcatServletWebServerFactory
factory
)
{
factory
.
addConnectorCustomizers
(
connector
->
connector
.
setAttribute
(
"relaxedQueryChars"
,
"{}[]|"
));
}
}
src/main/resources/application.properties
View file @
a91c2aeb
spring.profiles.active
=
prod
spring.profiles.active
=
dev
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