From 967bddd2de1fa36f7111b445f95f686a84ba676d Mon Sep 17 00:00:00 2001 From: yovinchen Date: Wed, 20 Sep 2023 17:07:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E7=AE=A1=E7=90=86=E7=AB=AF?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/compiler.xml | 2 + .idea/encodings.xml | 1 + guigu-ssyx-parent/pom.xml | 1 + guigu-ssyx-parent/service-gateway/pom.xml | 36 +++++++++++ .../ssyx/ServiceGatewayApplication.java | 22 +++++++ .../com/atguigu/ssyx/config/CorsConfig.java | 30 ++++++++++ .../src/main/resources/application-dev.yml | 59 +++++++++++++++++++ .../src/main/resources/application.yml | 11 ++++ .../ssyx/acl/controller/AdminController.java | 1 - .../ssyx/acl/controller/IndexController.java | 6 +- .../acl/controller/PermissionController.java | 2 +- .../ssyx/acl/controller/RoleController.java | 2 +- .../controller/ActivityInfoController.java | 2 +- .../controller/CouponInfoController.java | 2 +- .../product/controller/AttrController.java | 2 +- .../controller/AttrGroupController.java | 2 +- .../controller/CategoryController.java | 2 +- .../controller/FileUploadController.java | 3 +- .../product/controller/SkuInfoController.java | 2 +- .../src/main/resources/application.yml | 2 + .../src/main/resources/application.yml | 2 + .../ssyx/sys/controller/RegionController.java | 7 ++- .../sys/controller/RegionWareController.java | 1 - .../ssyx/sys/controller/WareController.java | 3 +- .../src/main/resources/application.yml | 2 + ssyx-admin/.env.development | 2 +- ssyx-admin/.env.production | 2 +- 27 files changed, 189 insertions(+), 20 deletions(-) create mode 100644 guigu-ssyx-parent/service-gateway/pom.xml create mode 100644 guigu-ssyx-parent/service-gateway/src/main/java/com/atguigu/ssyx/ServiceGatewayApplication.java create mode 100644 guigu-ssyx-parent/service-gateway/src/main/java/com/atguigu/ssyx/config/CorsConfig.java create mode 100644 guigu-ssyx-parent/service-gateway/src/main/resources/application-dev.yml create mode 100644 guigu-ssyx-parent/service-gateway/src/main/resources/application.yml diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 4cb390d..1a380cb 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -9,6 +9,7 @@ + @@ -29,6 +30,7 @@ + diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 171d535..d903963 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -10,6 +10,7 @@ + diff --git a/guigu-ssyx-parent/pom.xml b/guigu-ssyx-parent/pom.xml index 183a7bf..5664174 100644 --- a/guigu-ssyx-parent/pom.xml +++ b/guigu-ssyx-parent/pom.xml @@ -13,6 +13,7 @@ model service service-client + service-gateway diff --git a/guigu-ssyx-parent/service-gateway/pom.xml b/guigu-ssyx-parent/service-gateway/pom.xml new file mode 100644 index 0000000..64fd21b --- /dev/null +++ b/guigu-ssyx-parent/service-gateway/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + com.atguigu + guigu-ssyx-parent + 1.0-SNAPSHOT + + + service-gateway + + + com.atguigu + common-util + 1.0-SNAPSHOT + provided + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + 8 + 8 + UTF-8 + + + diff --git a/guigu-ssyx-parent/service-gateway/src/main/java/com/atguigu/ssyx/ServiceGatewayApplication.java b/guigu-ssyx-parent/service-gateway/src/main/java/com/atguigu/ssyx/ServiceGatewayApplication.java new file mode 100644 index 0000000..36e1c97 --- /dev/null +++ b/guigu-ssyx-parent/service-gateway/src/main/java/com/atguigu/ssyx/ServiceGatewayApplication.java @@ -0,0 +1,22 @@ +package com.atguigu.ssyx; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +/** + * ClassName: ServiceGatewayApplication + * Package: com.atguigu.ssyx + * + * @author yovinchen + * @Create 2023/9/20 16:51 + */ + +@SpringBootApplication +@EnableDiscoveryClient +public class ServiceGatewayApplication { + public static void main(String[] args) { + SpringApplication.run(ServiceGatewayApplication.class, args); + } + +} diff --git a/guigu-ssyx-parent/service-gateway/src/main/java/com/atguigu/ssyx/config/CorsConfig.java b/guigu-ssyx-parent/service-gateway/src/main/java/com/atguigu/ssyx/config/CorsConfig.java new file mode 100644 index 0000000..2fd3547 --- /dev/null +++ b/guigu-ssyx-parent/service-gateway/src/main/java/com/atguigu/ssyx/config/CorsConfig.java @@ -0,0 +1,30 @@ +package com.atguigu.ssyx.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.reactive.CorsWebFilter; +import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; +import org.springframework.web.util.pattern.PathPatternParser; + +/** + * ClassName: CorsConfig + * Package: com.atguigu.ssyx.config + * + * @author yovinchen + * @Create 2023/9/20 16:52 + */ +@Configuration +public class CorsConfig { + + @Bean + public CorsWebFilter corsFilter() { + CorsConfiguration config = new CorsConfiguration(); + config.addAllowedMethod("*"); + config.addAllowedOrigin("*"); + config.addAllowedHeader("*"); + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser()); + source.registerCorsConfiguration("/**", config); + return new CorsWebFilter(source); + } +} diff --git a/guigu-ssyx-parent/service-gateway/src/main/resources/application-dev.yml b/guigu-ssyx-parent/service-gateway/src/main/resources/application-dev.yml new file mode 100644 index 0000000..333ce1e --- /dev/null +++ b/guigu-ssyx-parent/service-gateway/src/main/resources/application-dev.yml @@ -0,0 +1,59 @@ +server: + port: 8200 + +spring: + cloud: + gateway: + discovery: + locator: + enabled: true + routes: + - id: service-acl + uri: lb://service-acl + predicates: + - Path=/*/acl/** + + - id: service-sys + uri: lb://service-sys + predicates: + - Path=/*/sys/** + + - id: service-product + uri: lb://service-product + predicates: + - Path=/*/product/** + + - id: service-activity + uri: lb://service-activity + predicates: + - Path=/*/activity/** + + - id: service-order + uri: lb://service-order + predicates: + - Path=/*/order/** + + - id: service-payment + uri: lb://service-payment + predicates: + - Path=/*/payment/** + + - id: service-user + uri: lb://service-user + predicates: + - Path=/*/user/** + + - id: service-search + uri: lb://service-search + predicates: + - Path=/*/search/** + + - id: service-home + uri: lb://service-home + predicates: + - Path=/*/home/** + + - id: service-cart + uri: lb://service-cart + predicates: + - Path=/*/cart/** diff --git a/guigu-ssyx-parent/service-gateway/src/main/resources/application.yml b/guigu-ssyx-parent/service-gateway/src/main/resources/application.yml new file mode 100644 index 0000000..ff78ad4 --- /dev/null +++ b/guigu-ssyx-parent/service-gateway/src/main/resources/application.yml @@ -0,0 +1,11 @@ +spring: + application: + name: service-gateway + profiles: + active: dev + cloud: + nacos: + discovery: + server-addr: 82.157.68.223:8848 + username: nacos + password: nacos diff --git a/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/AdminController.java b/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/AdminController.java index acfb18a..3bf4b19 100644 --- a/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/AdminController.java +++ b/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/AdminController.java @@ -30,7 +30,6 @@ import java.util.Map; @RestController @RequestMapping("/admin/acl/user") @Api(tags = "用户管理") -@CrossOrigin public class AdminController { @Autowired diff --git a/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/IndexController.java b/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/IndexController.java index 01daf24..e92d1ce 100644 --- a/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/IndexController.java +++ b/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/IndexController.java @@ -2,7 +2,10 @@ package com.atguigu.ssyx.acl.controller; import com.atguigu.ssyx.common.result.Result; import io.swagger.annotations.Api; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.Map; @@ -18,7 +21,6 @@ import java.util.Map; @Api(tags = "登录接口") @RestController @RequestMapping("/admin/acl/index") -@CrossOrigin //跨域 public class IndexController { /** diff --git a/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/PermissionController.java b/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/PermissionController.java index 02396ab..190cb54 100644 --- a/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/PermissionController.java +++ b/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/PermissionController.java @@ -22,7 +22,7 @@ import java.util.List; @RestController @RequestMapping("/admin/acl/permission") @Api(tags = "菜单服务") -@CrossOrigin + public class PermissionController { @Autowired diff --git a/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/RoleController.java b/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/RoleController.java index 7bdf2ce..6faf7a0 100644 --- a/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/RoleController.java +++ b/guigu-ssyx-parent/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/RoleController.java @@ -28,7 +28,7 @@ import java.util.Map; @RestController @RequestMapping("/admin/acl/role") @Api(tags = "角色管理") -@CrossOrigin + @Slf4j public class RoleController { diff --git a/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/ActivityInfoController.java b/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/ActivityInfoController.java index c324efb..22b64b6 100644 --- a/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/ActivityInfoController.java +++ b/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/ActivityInfoController.java @@ -25,7 +25,7 @@ import java.util.List; */ @Api(value = "ActivityInfo管理", tags = "活动管理") @RestController -@CrossOrigin + @RequestMapping("/admin/activity/activityInfo") public class ActivityInfoController { diff --git a/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/CouponInfoController.java b/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/CouponInfoController.java index 2cf7c79..5cf453c 100644 --- a/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/CouponInfoController.java +++ b/guigu-ssyx-parent/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/CouponInfoController.java @@ -22,7 +22,7 @@ import java.util.List; * @since 2023-09-17 */ @RestController -@CrossOrigin + @RequestMapping("/admin/activity/couponInfo") public class CouponInfoController { diff --git a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrController.java b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrController.java index 6b3eeb1..0587455 100644 --- a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrController.java +++ b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrController.java @@ -23,7 +23,7 @@ import java.util.List; @Api(value = "Attr管理", tags = "平台属性管理") @RestController @RequestMapping(value = "/admin/product/attr") -@CrossOrigin + public class AttrController { @Autowired diff --git a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrGroupController.java b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrGroupController.java index 99ff2f2..23a0aa1 100644 --- a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrGroupController.java +++ b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrGroupController.java @@ -26,7 +26,7 @@ import java.util.List; */ @Api(value = "AttrGroup管理", tags = "平台属性分组管理") @RestController -@CrossOrigin + @RequestMapping(value = "/admin/product/attrGroup") public class AttrGroupController { diff --git a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/CategoryController.java b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/CategoryController.java index 7886913..47cb68c 100644 --- a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/CategoryController.java +++ b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/CategoryController.java @@ -26,7 +26,7 @@ import java.util.List; */ @Api(value = "Category管理", tags = "商品分类管理") @RestController -@CrossOrigin + @RequestMapping(value = "/admin/product/category") public class CategoryController { diff --git a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/FileUploadController.java b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/FileUploadController.java index b06c0fd..130d3d8 100644 --- a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/FileUploadController.java +++ b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/FileUploadController.java @@ -5,7 +5,6 @@ import com.atguigu.ssyx.product.service.FileUploadService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -20,7 +19,7 @@ import org.springframework.web.multipart.MultipartFile; */ @Api(tags = "文件上传接口") @RestController -@CrossOrigin + @RequestMapping("admin/product") public class FileUploadController { diff --git a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuInfoController.java b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuInfoController.java index a6a7d66..a454d95 100644 --- a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuInfoController.java +++ b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuInfoController.java @@ -26,7 +26,7 @@ import java.util.List; */ @Api(value = "SkuInfo管理", tags = "商品Sku管理") @RestController -@CrossOrigin + @RequestMapping(value = "/admin/product/skuInfo") public class SkuInfoController { diff --git a/guigu-ssyx-parent/service/service-product/src/main/resources/application.yml b/guigu-ssyx-parent/service/service-product/src/main/resources/application.yml index 856ea6d..21199d2 100644 --- a/guigu-ssyx-parent/service/service-product/src/main/resources/application.yml +++ b/guigu-ssyx-parent/service/service-product/src/main/resources/application.yml @@ -7,3 +7,5 @@ spring: nacos: discovery: server-addr: 82.157.68.223:8848 + username: nacos + password: nacos diff --git a/guigu-ssyx-parent/service/service-search/src/main/resources/application.yml b/guigu-ssyx-parent/service/service-search/src/main/resources/application.yml index 3bec5db..14b72c5 100644 --- a/guigu-ssyx-parent/service/service-search/src/main/resources/application.yml +++ b/guigu-ssyx-parent/service/service-search/src/main/resources/application.yml @@ -7,3 +7,5 @@ spring: nacos: discovery: server-addr: 82.157.68.223:8848 + username: nacos + password: nacos diff --git a/guigu-ssyx-parent/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionController.java b/guigu-ssyx-parent/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionController.java index 6ac2c2f..0dc6ce3 100644 --- a/guigu-ssyx-parent/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionController.java +++ b/guigu-ssyx-parent/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionController.java @@ -7,7 +7,10 @@ import com.atguigu.ssyx.sys.service.RegionService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -22,7 +25,7 @@ import java.util.List; @Api(value = "地区接口", tags = "地区接口") @RestController @RequestMapping("/admin/sys/region") -@CrossOrigin + public class RegionController { @Autowired diff --git a/guigu-ssyx-parent/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionWareController.java b/guigu-ssyx-parent/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionWareController.java index 7093540..e76ce93 100644 --- a/guigu-ssyx-parent/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionWareController.java +++ b/guigu-ssyx-parent/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionWareController.java @@ -24,7 +24,6 @@ import org.springframework.web.bind.annotation.*; @RestController @RequestMapping(value = "/admin/sys/regionWare") @Api(value = "开通区域接口", tags = "开通区域接口") -@CrossOrigin public class RegionWareController { @Autowired private RegionWareService regionWareService; diff --git a/guigu-ssyx-parent/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/WareController.java b/guigu-ssyx-parent/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/WareController.java index c4c9b49..f9e4a95 100644 --- a/guigu-ssyx-parent/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/WareController.java +++ b/guigu-ssyx-parent/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/WareController.java @@ -7,7 +7,6 @@ import com.atguigu.ssyx.sys.service.WareService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -25,7 +24,7 @@ import java.util.List; @Api(value = "仓库接口", tags = "仓库接口") @RestController @RequestMapping("/admin/sys/ware") -@CrossOrigin + public class WareController { @Autowired diff --git a/guigu-ssyx-parent/service/service-sys/src/main/resources/application.yml b/guigu-ssyx-parent/service/service-sys/src/main/resources/application.yml index bbe8496..2bafd13 100644 --- a/guigu-ssyx-parent/service/service-sys/src/main/resources/application.yml +++ b/guigu-ssyx-parent/service/service-sys/src/main/resources/application.yml @@ -7,3 +7,5 @@ spring: nacos: discovery: server-addr: 82.157.68.223:8848 + username: nacos + password: nacos diff --git a/ssyx-admin/.env.development b/ssyx-admin/.env.development index f9082c0..3e1a4ef 100644 --- a/ssyx-admin/.env.development +++ b/ssyx-admin/.env.development @@ -3,4 +3,4 @@ ENV = 'development' # base api # VUE_APP_BASE_API = '/dev-api' -VUE_APP_BASE_API = 'http://localhost:9001' +VUE_APP_BASE_API = 'http://localhost:8200' diff --git a/ssyx-admin/.env.production b/ssyx-admin/.env.production index 91b93c6..870addf 100644 --- a/ssyx-admin/.env.production +++ b/ssyx-admin/.env.production @@ -3,5 +3,5 @@ ENV = 'production' # base api #VUE_APP_BASE_API = '/prod-api' -VUE_APP_BASE_API = 'http://localhost:9001' +VUE_APP_BASE_API = 'http://localhost:8200'