【发布时间】:2020-04-17 14:23:32
【问题描述】:
我目前正在使用 Micronaut 构建一个微服务。现在我想添加 CORS 支持。目前我的 application.yml 看起来像这样:
micronaut:
application:
name: gateway
server:
port: ${HTTP_PORT:8080}
cors:
enabled: true
configurations:
web:
allowedOrigins:
- http://localhost:8080
有没有办法将 allowedOrigins 作为数组从环境变量中传递?
【问题讨论】:
-
你试过
MICRONAUT_SERVER_CORS_CONFIGURATIONS_WEB_ALLOWED_ORIGINS="http://localhost:8080,http://localhost:8081"吗? -
感谢您的回复。我试过这个,但它只适用于单个主机,如果我添加两个主机,它就不起作用。我的 application.yml 中有这样的:
allowedOrigins: ${CORS_ALLOWED_ORIGINS}和 env:CORS_ALLOWED_ORIGINS=http://localhost:4000,http://localhost:4001