I have a Node.js app that I wrote and successfully deployed to a Heroku app via Bash. From my computer running Ubuntu at home it runs fine locally too.
However, I have just cloned the repository to a Windows machine and while I've successfully managed to push updates to the Heroku remote, which work, whenever I run heroku local
from Windows and try to access the local version (localhost:5000), that page serves an error and my command line returns TypeError: Request path contains unescaped characters
and layer.js:95.5
.
The app uses https.get
and this seems to be the problem line, locally.
I'm reluctant to try adapting my code since it works fine on Heroku itself and works fine on my Ubuntu machine -- so can only assume that something needs configuring on my Windows machine.
Any idea what the problem might be?
Be careful which variable keys you choose for config/ .env
in Heroku. Windows has some reserved keys (like user
and path
) which will mean trying to set your own values against these keys will not work.
It turns out the issue is with my choice of variable names as used in my .env
file.
When you have data that you don't want to commit to a repository (in my case, an authentication key and details for my account) you can add them to Heroku as "config vars" -- key=value
pairs which Heroku keeps separate to your code so you can version and share your repository as needed and others can add their own details.
When running Heroku locally however using the heroku local
command from the toolbelt, these variables need to come from somewhere else. Heroku's help recommends setting them up as key=value
pairs in a file called .env
(which you can then add to .gitignore
to prevent accidental committing.
Unfortunately, in my case it was my choice of variable keys in .env
that caused the problem. I had created dependencies on variables called user
and path
but these seem to be reserved on Windows and have a special purpose and therefore could not be overwritten by what was in my .env
file. This is why what worked for me on my Ubuntu machine would not work directly on Windows.
You can see this in action by calling console.log( process.env.user
, process.env.path
) from Node on a Windows machine.
Now that I have changed the variable names to something non-reserved heroku local
works fine. Calling the programme via node
command will still not work as it is not set up to pick up the variables from .env
as Heroku.
Hope this helps someone else.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.