ryansurf / cli-surf

Get surf and ocean data from the command line interface
7 stars 10 forks source link

Storing JavaScript variables in .env file #15

Closed ryansurf closed 2 months ago

ryansurf commented 2 months ago

The top lines of src/frontend/script.js has: const ipAddress = 'localhost'; and const port = 8000;. I think it would be best to store these variables in the .env file in the root of the project

We should be able to load in the variables from the .env file in our JavaScript, like: const ipAddress = env.IPADDRESS, or however you would do that.

K-dash commented 2 months ago

@ryansurf Hai! I noticed you changed the backend to Flask. I think that's a good move!

Since you switched to Flask, you can return index.html as a template engine. By using a template engine, you can pass environment variables to script.js via HTML.

I'll take care of this:)

ryansurf commented 2 months ago

@K-dash Hello! httpserver was being a pain, Flask is much better haha

I was messing with a few things last night, and decided to pass the variables in from the config.json file, not the .env anymore. Flask servers the config.json, which is where script.js now accesses those variables(see the first 25 lines of script.js.

What do you think, is that the right move? Or is your idea the more elegant solution?

K-dash commented 2 months ago

@ryansurf Yeah, I was also thinking that httpserver needed improvement (lol)

I was messing with a few things last night, and decided to pass the variables in from the config.json file, not the .env anymore. Flask servers the config.json, which is where script.js now accesses those variables(see the first 25 lines of script.js.

I took a look at your implementation! However, I believe my implementation is more appropriate because it's simpler, requires less code, and follows Flask's usage conventions. Also, having both config.json and .env files for managing environment variables felt a bit odd to me, so I thought about unifying them into .env. I've submitted a PR, so please review it!

https://github.com/ryansurf/cli-surf/pull/19

ryansurf commented 2 months ago

Good points, seems like that's the move then. I'll take a look/approve your PR when I get home later today😎

Good work! Seems like you know what you're doing haha