提交 94cb809d 作者: 方治民

feat: add cors, context-path ...

上级 847c32bc
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 跨域配置
*
* @author Jim
* @version 0.1
* 2022/1/19 15:17
*/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*")
.allowedHeaders("*")
.exposedHeaders("Content-Disposition");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
server: server:
port: 8080 port: 8080
servlet: servlet:
context-path: / context-path: /api
spring: spring:
application: application:
......
...@@ -47,7 +47,10 @@ public class SwaggerConfig { ...@@ -47,7 +47,10 @@ public class SwaggerConfig {
String applicationName; String applicationName;
@Value("${server.port}") @Value("${server.port}")
String serverPort; String port;
@Value("${server.servlet.context-path}")
String path;
@Resource @Resource
OpenApiExtensionResolver openApiExtensionResolver; OpenApiExtensionResolver openApiExtensionResolver;
...@@ -58,7 +61,7 @@ public class SwaggerConfig { ...@@ -58,7 +61,7 @@ public class SwaggerConfig {
} }
private Docket api(Predicate<String> paths) { private Docket api(Predicate<String> paths) {
log.info("API Doc: http://localhost:{}/doc.html", serverPort); log.info("API Doc: http://localhost:{}{}/doc.html", port, path);
String group = "default"; String group = "default";
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2)
......
...@@ -108,6 +108,9 @@ subprojects { ...@@ -108,6 +108,9 @@ subprojects {
} }
} }
// format
spotlessApply
// GitHook pre-commit (spotless, spotbugs) // GitHook pre-commit (spotless, spotbugs)
def hook = new File("$rootProject.projectDir/.git/hooks/pre-commit") def hook = new File("$rootProject.projectDir/.git/hooks/pre-commit")
hook.text = """#!/bin/bash hook.text = """#!/bin/bash
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论