apotdevin / thunderhub

ThunderHub LND Lightning Node Manager in your Browser
https://www.thunderhub.io/
MIT License
415 stars 88 forks source link

Are .env files only loaded for docker builds? #226

Open bumi opened 3 years ago

bumi commented 3 years ago

I tried to run thunderhub master directly on my machine (not through docker) and somehow assumed that the .env files get loaded when the app gets started using yarn start. It seems those files get not loaded automatically. Is that correct?

Maybe we could use dotenv to load those or maybe this should be made more clear in the readme?

Your environment

To Reproduce Steps to reproduce the behavior:

  1. Clone the repo
  2. npm install
  3. Edit .env and/or .env.local
  4. npm build && npm start

Expected behavior Environment variables (specifically ACCOUNT_CONFIG_PATH) should be loaded.

I was also wondering if it makes sense to use a default for ACCOUNT_CONFIG_PATH (e.g. ./thubConfig.yaml). Accounts are always required and then it is easy for people to simply add the thubConfig.yaml file and no .env file edit is needed.

Actual behavior .env files are ignored

apotdevin commented 3 years ago

Hey! They are loaded by default by ThunderHub even if not in a docker container. The files have to be in the root folder of thunderhub. It will load first .env.local if it exists and if not then it loads the .env file.

Any more specific details since following your steps I can't reproduce this issue

bumi commented 3 years ago

thanks for your reply and help! hmm. I somehow can not get it to work. here are the details:

bitcoin@host:~/thunderhub $ ls -al ./.env*
-rw-rw-r-- 1 bitcoin bitcoin 1197 Mar 15 10:23 ./.env
-rw-rw-r-- 1 bitcoin bitcoin 1139 Mar 15 21:17 ./.env.local
bitcoin@host:~/thunderhub $ cat ./.env.local
ACCOUNT_CONFIG_PATH="/home/bitcoin/thunderhub/thubConfig.yaml"
bitcoin@host:~/thunderhub $
bitcoin@bullet:~/thunderhub$ cat thubConfig.yaml
defaultNetwork: testnet
masterPassword: thunderhub-aasdasd
accounts:
  - name: Account1
    serverUrl: 127.0.0.1:10009
    macaroonPath: /home/bitcoin/lnd/data/chain/bitcoin/testnet/admin.macaroon
    certificatePath: /home/bitcoin/lnd/tls.cert

I've added a console.log to next.config.js

diff --git a/next.config.js b/next.config.js
index aee9237..8978903 100644
--- a/next.config.js
+++ b/next.config.js
@@ -29,6 +29,8 @@ const accountConfig = {
   accountConfigPath: process.env.ACCOUNT_CONFIG_PATH || '',
 };

+console.log(accountConfig);
+

Running next start

bitcoin@host:~/thunderhub$ next start
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
{ accountConfigPath: '' }
info  - Loaded env from /home/bitcoin/thunderhub/.env.local
info  - Loaded env from /home/bitcoin/thunderhub/.env

If I open localhost:3000 it tells me to setup accounts.

now when I run next start providing the env variable I get:

bitcoin@host:~/thunderhub $ ACCOUNT_CONFIG_PATH="/home/bitcoin/thunderhub/thubConfig.yaml" next start
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
{ accountConfigPath: '/home/bitcoin/thunderhub/thubConfig.yaml' }
info  - Loaded env from /home/bitcoin/thunderhub/.env.local
info  - Loaded env from /home/bitcoin/thunderhub/.env

and it works...

what am I missing?