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.

Doesn't work with absolute paths

See original GitHub issue

Assuming there is a file named ‘index.html’ in the directory, accessing the server at localhost:3000 returns a 404 Not Found with the code below. Note that the file does exist and the path is correct, as demonstrated by the fs.statSync call.

const app = require('koa')();
const send = require('koa-send');
const fs = require('fs');

const INDEX_FILE = `${__dirname}/index.html`;
// This string is an absolute path, e.g. in my case "/home/miguel/Programming/koa-send-test/index.html"

app.use(function*() {
    console.log(fs.statSync(INDEX_FILE)); //Returns a valid object
    yield send(this, INDEX_FILE); //Does nothing
});

app.listen(3000);

However if INDEX_FILE is set to a relative path, the code works fine and returns index.html when accessing localhost:3000

const INDEX_FILE = `index.html`;

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
GreenGremlincommented, Dec 23, 2015

It is that way to make sure developers don’t inadvertently give access to the root file system. You can do what you’re asking by setting the root option.

app.use(function*() {
    yield send(this, 'index.html', { root:'/var/www' });
});
0reactions
multimericcommented, Dec 23, 2015

Ohhh I see. My first example was using an absolute path when it expects a path relative to the root, so we had to set root to ‘/’ for it to make sense.

Okay this behaviour makes a lot of sense. I think it’s just the documentation that’s confusing. I might get around to a PR if I get the time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

css - relative path - absolute path not working? - Stack Overflow
1 Answer 1 · My answer is correct, that is how to use an image from the img folder in the root of...
Read more >
tsconfig absolute paths not working · Issue #1144 - GitHub
Qwik Version "@builder.io/qwik": "0.0.105", "@builder.io/qwik-city": "0.0.105", Operating System (or Browser) Win 11 Node Version (if ...
Read more >
What are the differences between absolute and relative paths?
Absolute paths are useful, but they're not always efficient. If you know where the widgets directory, which contains button , is located. then ......
Read more >
File.relativeTo doesn't work when mixing absolute and relative ...
When using File objects where one is using an absolute path and one is using a relative path from the working directory, File....
Read more >
Convert relative paths to be absolute paths not working for CSS
Problem /Motivation When the checkbox for Convert relative paths to be absolute paths is checked, the CSS files are not converted to absolute ......
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