简体   繁体   English

配置变量在Heroku应用中不可视为环境变量

[英]Config variables not visible as environment variables in Heroku app

I've set a few custom config variables. 我设置了一些自定义配置变量。 I can see them in my application's settings->config variables. 我可以在应用程序的settings-> config变量中看到它们。 I can also see the values with the heroku config command. 我还可以使用heroku config命令查看这些值。 But when I start my application the environment variables are not there. 但是,当我启动应用程序时,环境变量不存在。 I use (System/getenv "MY_VARIABLE_NAME") in Clojure to fetch them. 我在Clojure中使用(System / getenv“ MY_VARIABLE_NAME”)来获取它们。

Is it because I try to retrieve them at boot time? 是因为我尝试在引导时检索它们吗? Are they only available later? 以后才有吗? Or is there some twitch which I can get rid of by doing some trick? 还是有一些我可以通过做一些技巧摆脱的抽搐? I've used config variables in Heroku before and they've worked, I don't know what's the problem here... 我之前在Heroku中使用过配置变量,但它们已经起作用了,我不知道这里出了什么问题...

I was trying to retrieve client ID and secret for oauth authentication with Google from a config variable with System/getenv. 我试图从System / getenv的配置变量中检索客户端ID和用于Google进行oauth身份验证的密码。 I use a library called Friend to do this. 我使用一个名为Friend的库来做到这一点。 Problem is, the set up for oauth parameters in that library is done via macros. 问题是,该库中的oauth参数设置是通过宏完成的。 And macro expansion happens compile-time. 宏扩展发生在编译时。 Heroku config variables are not available as environment variables during compilation (for good reasons). Heroku配置变量在编译期间不可用作环境变量(有充分的理由)。 They are, however available via filesystem which was my solution to the problem. 但是,可以通过文件系统使用它们,这是我解决该问题的方法。 So instead of: 所以代替:

(System/getenv "MY_APP_GOOGLE_CLIENT_ID")

I'm using this: 我正在使用这个:

(slurp (str (System/getenv "ENV_DIR") "/" "MY_APP_GOOGLE_CLIENT_ID"))

And it works! 而且有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM