瀏覽代碼

simple rest

herlanS_ 5 年之前
父節點
當前提交
ca877f2b9e
共有 1 個文件被更改,包括 12 次插入0 次删除
  1. 12 0
      src/main/kotlin/com/kawanansemut/demoangular/DemoAngularApplication.kt

+ 12 - 0
src/main/kotlin/com/kawanansemut/demoangular/DemoAngularApplication.kt

@@ -5,8 +5,11 @@ import com.kawanansemut.demoangular.entities.UserRepository
 import org.springframework.boot.autoconfigure.SpringBootApplication
 import org.springframework.boot.context.event.ApplicationReadyEvent
 import org.springframework.boot.runApplication
+import org.springframework.context.annotation.Configuration
 import org.springframework.context.event.EventListener
 import org.springframework.stereotype.Component
+import org.springframework.web.servlet.config.annotation.CorsRegistry
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
 
 @SpringBootApplication
 class DemoAngularApplication
@@ -30,3 +33,12 @@ class justAfterStart(
 
 
 }
+
+@Configuration
+class MvcConfig : WebMvcConfigurer {
+
+	override fun addCorsMappings(registry: CorsRegistry) {
+		registry.addMapping("/**").allowedMethods("GET", "POST", "PUT", "DELETE").allowedOrigins("*")
+				.allowedHeaders("*")
+	}
+}