question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a leading / if the path doesn't have it

See original GitHub issue

Recently, we bumped into an issue with nock in which it won’t catch a request we were sure was being mocked correctly. We were wondering for a while until .log(console.log) shed some light on what the issue was.

We noticed our host url didn’t have a trailing slash (http://localhost:3000) while at the same time our mocked path didn’t have a leading slash (api/bot/request.json). Turns out knock was trying to match our url with http://localhost:3000api/bot/request.json, no slash separating the host and path segments.

I was wondering if we can have nock add that slash by itself when is not present.

I can submit a PR if you guys want.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
kevinniocommented, Jan 20, 2019

Sorry, I’ve been quite busy since the end of last year. I’m going to spend some time working on this tomorrow.

1reaction
kevinniocommented, Jan 24, 2019

Given https://github.com/nock/nock/pull/1391#discussion_r250725610, we decided to make nock raise an error whenever the user forgets to add a leading slash into the intercepted path, instead of adding it itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add directory to $PATH if it's not already there - Super User
If I construct my PATH in .bashrc, then it runs with each subshell. So if I launch a Terminal window and then run...
Read more >
urljoin when an absolute path does not have a leading slash
python - urljoin when an absolute path does not have a leading slash - Stack Overflow. Stack Overflow for Teams – Start collaborating...
Read more >
How to correctly add a path to PATH? - Unix Stack Exchange
The simple stuff. PATH=$PATH:~/opt/bin. or. PATH=~/opt/bin:$PATH. depending on whether you want to add ~/opt/bin at the end (to be searched ...
Read more >
OperatingSystem - Robot Framework
If the path to the file does not exist, it is created. The resulting destination path is returned. See also Copy Files, Move...
Read more >
ansible.builtin.file module – Manage files and file properties
This module is part of ansible-core and included in all Ansible installations. ... Note that absent will not cause file to fail if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found