这是我最终使用的,因为我似乎无法以良好的顺序进行变量替换。鉴于 CORS Allowed Origins 的 Play Framework HOCON 部分,它允许本地、开发、阶段和生产部署,并且不符合 12 因素:
play {
# https://www.playframework.com/documentation/2.5.x/resources/confs/filters-helpers/reference.conf
filters {
# use default values for gzip, csrf & security headers
# setup cors
cors {
# whitelist all paths
pathPrefixes = ["/"]
allowedOrigins = [
"http://localhost:8080"
"http://app.127.0.0.1.nip.io:8080"
"http://app.192.168.64.2.nip.io"
"http://app.192.168.42.173.nip.io"
"http://app.terradatum.local"
"http://app.dev.terradatum.com"
"https://app.dev.terradatum.com"
"http://app.stage.terradatum.com"
"https://app.stage.terradatum.com"
"http://app.terradatum.com"
"https://app.terradatum.com"
]
}
}
}
我已经尝试了以下两种 HOCON,环境设置也如图所示:
# HOCON
allowedOrigins = ${?APP_ALLOWED_ORIGINS}
# ENV
export APP_ALLOWED_ORIGINS='"http://app.127.0.0.1.nip.io:8080","http://app.192.168.64.2.nip.io","http://app.192.168.42.173.nip.io","http://app.terradatum.local","http://app.dev.terradatum.com","https://app.dev.terradatum.com","http://app.stage.terradatum.com","https://app.stage.terradatum.com","http://app.terradatum.com","https://app.terradatum.com"'
和...
# HOCON
allowedOrigins = [
${?APP_ALLOWED_ORIGINS}
"http://app.127.0.0.1.nip.io:8080"
"http://app.192.168.64.2.nip.io"
"http://app.192.168.42.173.nip.io"
"http://app.terradatum.local"
"http://app.dev.terradatum.com"
"https://app.dev.terradatum.com"
"http://app.stage.terradatum.com"
"https://app.stage.terradatum.com"
"http://app.terradatum.com"
"https://app.terradatum.com"
]
# ENV
export APP_ALLOWED_ORIGINS="http://some-new-cors.terradatum.com\nhttps://some-new-cors.terradatum.com\n"
许多其他 CORS 实现允许使用正则表达式,而 WTH 不起作用?
除此之外,列表的 HOCON 处理对我来说非常有问题......上面的第一个实现工作,但是任何迭代我有一个现有的默认列表application.conf
失败......
通过环境变量替换向 HOCON 添加列表或列表项的推荐方法是什么?