nightscout / cgm-remote-monitor

nightscout web monitor
GNU Affero General Public License v3.0
2.36k stars 71.35k forks source link

my.env requires to URL-encode all variables, but CUSTOM_TITLE is not URLDecoded when being displayed #8198

Closed petwall closed 6 months ago

petwall commented 6 months ago

If you need support for Nightscout, PLEASE DO NOT FILE A TICKET HERE For support, please post a question to the "CGM in The Cloud" group in Facebook (https://www.facebook.com/groups/cgminthecloud) or visit the WeAreNotWaiting Discord at https://discord.gg/zg7CvCQ

Describe the bug I run Nightscout on Ubuntu, which requires all variables specified in my.env to be URLencoded.

I set CUSTOM_TITLE=MySons%20Name It's being rendered as 'MySons%20Name' instead of 'MySons Name'

To Reproduce Steps to reproduce the behavior:

  1. Set CUSTOM_TITLE to something with a space encoded with %20
  2. see the title of the nightscout site contain a visible %20 instead of a space

Expected behavior Rendered with a space: 'The Name' instead of 'The%20Name'

Screenshots If applicable, add screenshots to help explain your problem.

Your setup information

Additional context I guess an easy/safe fix for this would be to do something like this (didn't know exactly how to contribute with code properly, will look into that :-) )

% git diff index.js diff --git a/lib/client/index.js b/lib/client/index.js index 0f0d17b7..fb5d8066 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -392,6 +392,7 @@ client.load = function load (serverSettings, callback) {

function resetCustomTitle () { var customTitle = client.settings.customTitle || 'Nightscout';

Screenshot before/after the fix on my nightscout instance

image

image

sulkaharo commented 6 months ago

The script that reads in my.env is a Node script, which should run identically across platforms, are you sure you're not confusing between the command line Ubuntu behaviour and the env file? Regardless, if you want to set variables with a space in the value, I'd recommend using quotes, so try CUSTOM_TITLE="MySons Name" as a line in the file.

petwall commented 6 months ago

Yes, got it. As you say, the problem here is the way Nightscout is started on Ubuntu (with the command line as below), which does not allow CUSTOM_TITLE="Name Name" as a format.

pw@jidder:~/nightscout$ env $(cat my.env)  PORT=1337 pm2 start server.js
env: ‘Name"’: No such file or directory
petwall commented 6 months ago

@sulkaharo do you mean on other platforms that nightscout is not relying on environmental variables, but actually parse the my.env variables when the server is started? (it seems from the other guides for Heroku and others, that the config is about setting up the environment variables on the hosting system?)

Anyway, on Ubuntu, I stumbled into some severe problems with the way env is being used to read the config -- in the end I had to place some complex variables as LOOP_APNS_KEY in my .profile instead, since URL-encoding it the right way was tricky...

petwall commented 6 months ago

Ok, from what I can see, the my.env file is never parsed, but the config is being read from the environment. I solved it in the following way for Ubuntu, I installed dotenv-cli npm install -g dotenv-cli and then started the server with the following command instead: dotenv -e my.env -- pm2 start server.js Then it's fully possible to use quotation + spaces in the my.env file... this is most likely a better approach.

petwall commented 6 months ago

Anyhow, I see that this has nothing to do with the nightscout code itself to do, but how the environment is set up on Ubuntu. Since there are several ways to resolve this with the way nightscout is invoked, this issue can be resolved as invalid.

petwall commented 6 months ago

Closing