Skip to content

Commit

Permalink
Merge pull request #5 from chris-schmitz/cors
Browse files Browse the repository at this point in the history
Adds initial cors configuration
  • Loading branch information
chris-schmitz authored Dec 31, 2023
2 parents 5993d78 + f9437a4 commit 34c03db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.lightinspiration.matrixanimatorapi.configuration

import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.CorsRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

@Configuration
class CorsConfiguration {

@Bean
fun configureCors(@Value("\${cors.allowed-origins}") allowedOrigins: String): WebMvcConfigurer {
return object : WebMvcConfigurer {
override fun addCorsMappings(registry: CorsRegistry) {
registry
.addMapping("/rest/animations/**")
.allowedOrigins(allowedOrigins)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true)
}
}
}
}
6 changes: 4 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ spring:
schmitz-sandbox:
# ! Note that the host is `database` which is the name of the database service running
# ! postgres in docker-compose.yml
jdbc-url: jdbc:postgresql://database:5432/postgres
jdbc-url: jdbc:postgresql://localhost:5433/postgres
# jdbc-url: jdbc:postgresql://database:5432/postgres
username: postgres
password: password # TODO: figure out how to pull this out to .env and inject it on launch. gradle task??
driver-class-name: org.postgresql.Driver


cors:
allowed-origins: http://localhost:8081

0 comments on commit 34c03db

Please sign in to comment.