Giter Club home page Giter Club logo

Comments (4)

evanshortiss avatar evanshortiss commented on May 27, 2024 1

@nirsky this will be addressed in docs in 6.2.0

from env-var.

evanshortiss avatar evanshortiss commented on May 27, 2024

Internally asUrlString() uses the url module from Node.js core (which implements WHATWG URL), and that adds the trailing slash.

Here's an example from Node.js v14.3.0.

new URL('http://a.b.com').toString()
'http://a.b.com/'
new URL('http://a.b.com/hello').toString()
'http://a.b.com/hello'

I feel like it makes sense to add the trailing slash, since in reality you're making a request to /. Perhaps this should be noted in the README?

from env-var.

nirsky avatar nirsky commented on May 27, 2024

Probably worth mentioning. I spent a couple of minutes trying to understand why my request is failing.

from env-var.

evanshortiss avatar evanshortiss commented on May 27, 2024

@nirsky gotcha, I think a PR in docs reminding developers to use the URL module/class when working with URLs is a good idea, e.g instead of:

var path = '/thing'
var baseUrl = env.get('MY_URL').asUrlString()

// Could create invalid URL with two slashes!
var fullUrl = baseUrl + path

doing this:

var path = '/thing'
var baseUrl = env.get('MY_URL').asUrlString()

// Will be correct, with no double forward slashes
var fullUrl = new URL(path, baseUrl).toString()

Would you like to PR it?

from env-var.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.