quirrel-dev / quirrel

The Task Queueing Solution for Serverless.
https://quirrel.dev
MIT License
896 stars 66 forks source link

QUIRREL_BASE_URL environment variable not working in development #1028

Closed rmiller61 closed 2 years ago

rmiller61 commented 2 years ago

Bug Report

Current Behavior I'm using local-ssl-proxy for development which means my base url is https://localhost:3000. But no matter what I set QUIRREL_BASE_URL to in my .env files, Quirrel seems to still use the default (insecure) http://localhost:3000 as the base url. As a result, my queues/events are not working.

Input Code

.env

QUIRREL_BASE_URL="https://localhost:3000"

package.json

  "scripts": {
    "dev": "concurrently 'blitz dev -p 3001 & local-ssl-proxy --key localhost-key.pem --cert localhost.pem --source 3000 --target 3001' 'quirrel'",
    ...
  },

Expected behavior/code Quirrel should be using the environment variable I've set for the base url.

Environment

Possible Solution

Additional context/Screenshots In the development UI, on the network tab it is showing the wrong (default) base URL being called.

Screen Shot 2022-08-17 at 9 31 03 PM
Skn0tt commented 2 years ago

Judging from the code you sent, it looks like you should be using https://localhost:3001. Does that work?

rmiller61 commented 2 years ago

Nope I've tried every variation of https:// vs http://, port 3000 vs 3001. The problem seems to be that Quirrel is ignoring my QUIRREL_BASE_URL environment variable. At least that's what my assumption would be from that screenshot of the network tab where the url param is always http://localhost:3000 regardless of what the environment variable is.

Skn0tt commented 2 years ago

The QUIRREL_BASE_URL variable is picked up by the Quirrel npm library you're importing in your Blitz app. Can you check if other environment variables from that file are being picked up by Blitz?

Skn0tt commented 2 years ago

Aside from that, could you elaborate on why you're trying to guard Quirrel behind an SSL proxy locally? Would love to learn more about that.

rmiller61 commented 2 years ago

Yeah all other environment variables are working and if I console.log(process.env.QUIRREL_BASE_URL) on the server it prints the correct value.

As for the SSL, I actually don't even remember why I'm using a proxy. If I start my application without the proxy, with just concurrently 'blitz dev' 'quirrel' then everything does work as intended (in retrospect that was probably worth mentioning in the bug report, so apologies on not making that clear).

Regardless, I still thought this was worth opening the issue because it does seem Quirrel is ignoring the environment variable, and if that's the case I'm concerned what will happen in production when I try to set the variable.

Skn0tt commented 2 years ago

When you write "the application seems to still use the default" in the issue, what is "the application" referring to, Quirrel or your Blitz application?

Skn0tt commented 2 years ago

If it's referring to Quirrel, I think I have an idea of what's causing what you're seeing, and it checks out that you're seeing the Dev UI call the local quirrel server via HTTP and not HTTPS. In local dev, I consider that very acceptable. Can you elaborate on why that's a problem for your usecase?

rmiller61 commented 2 years ago

I mean Quirrel. I've updated the description for clarity.

I don't think HTTPS is the issue. Even if I stop using the proxy, Quirrel still won't call any url other than http://localhost:3000. For example, if I set QUIRREL_BASE_URL="http://localhost:3001" and start with blitz dev -p 3001, Quirrel still uses a http://localhost:3000 endpoint even though the server is http://localhost:3001.

Like I said, it's not necessarily a problem in development because I can just not use proxies or port forwarding. But this does seem to go against the expected behavior of Quirrel. And I'm concerned that if the environment variable doesn't work in development, then it won't in production, which would be a problem.

Skn0tt commented 2 years ago

I think the problem is that in your dev script, the 'quirrel' call won't pick up .env files. Could you try changing it to 'QUIRREL_BASE_URL="http://localhost:3001" quirrel'? That should make it pick up the environment variable. Alternative, you can look at tools like https://www.npmjs.com/package/dotenv-cli.

rmiller61 commented 2 years ago

perfect, that worked. Much thanks! I'll mark this as closed.