Skip to content

Instantly share code, notes, and snippets.

@manchicken
Created October 15, 2021 14:36
Show Gist options
  • Save manchicken/12c55a94bd03166ff33ed0596263b4c6 to your computer and use it in GitHub Desktop.
Save manchicken/12c55a94bd03166ff33ed0596263b4c6 to your computer and use it in GitHub Desktop.
url-string-antipattern-before-1
const { URL } = require('url')
const encodeUrl = require('encodeurl')
const BASE_URL = 'https://api.foobar.com/api/bookmark'
const bookmark_url = 'https://www.reddit.com/r/chickens/search/?q=silkie&restrict_sr=1'
const constructed_url = `${BASE_URL}/?url=${encodeUrl(bookmark_url)}`
console.log(new URL(constructed_url))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment