-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev-midi-generator' of https://github.com/SleepyLGod/om…
…g-score into dev-midi-generator
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...tion/pianotranscriptioncli/src/main/java/com/pianotranscriptioncli/config/CorsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.pianotranscriptioncli.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
import org.springframework.web.filter.CorsFilter; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class CorsConfig implements WebMvcConfigurer { | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") // 项目中的所有接口都支持跨域 | ||
.allowedOriginPatterns("*") // 所有地址都可以访问,也可以配置具体地址 | ||
.allowCredentials(true) | ||
.allowedMethods("*") // "GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS" | ||
.maxAge(360000); // 跨域允许时间 | ||
} | ||
|
||
@Bean | ||
public CorsFilter corsFilter() { | ||
// 1.添加CORS配置信息 | ||
CorsConfiguration config = new CorsConfiguration(); | ||
// 放行哪些原始域 | ||
config.addAllowedOrigin("*"); | ||
// 是否发送Cookie信息 | ||
config.setAllowCredentials(true); | ||
// 放行哪些原始域(请求方式) | ||
config.addAllowedMethod("*"); | ||
// 放行哪些原始域(头部信息) | ||
config.addAllowedHeader("*"); | ||
// 暴露哪些头部信息(因为跨域访问默认不能获取全部头部信息) | ||
config.addExposedHeader("*"); | ||
|
||
// 2.添加映射路径 | ||
UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource(); | ||
configSource.registerCorsConfiguration("/**", config); | ||
|
||
// 3.返回新的CorsFilter. | ||
return new CorsFilter(configSource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
OmgPianoTranscription/pianotranscriptioncli/src/main/resources/test.http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters