Doesn't work with absolute paths
See original GitHub issueAssuming 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:
- Created 8 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.