Giter VIP home page Giter VIP logo

Comments (8)

 avatar commented on April 28, 2024 1

@thornjad yes, thank you for the explanation. I just ended up deploying the dist files to the public directory.

The security implication makes perfect sense. I didn't think that all the way through.

from http-server.

michaelsbradleyjr avatar michaelsbradleyjr commented on April 28, 2024

Does the link work improperly when you've loaded http://domain/page/index.html or the "auto-index" at http://domain/page or http://domain/page/ (note the trailing /), or all three?

from http-server.

zephor avatar zephor commented on April 28, 2024

hmm good point, only fails on the http://domain/page

Works with the trailing /

Seems its a problem with ecstatic, when I tried it with just union and ecstatic 0.1.x it did the same thing. Bumping up the version to 0.3.x fixed this.

from http-server.

michaelsbradleyjr avatar michaelsbradleyjr commented on April 28, 2024

Pull request #38 closes this issue.

from http-server.

zephor avatar zephor commented on April 28, 2024

fixed in 0.5.5

from http-server.

 avatar commented on April 28, 2024

This is a different use case. But files that reside outside of the public directory that are referenced by index.html in public/index.html cannot be resolved, and are resolving to absolute paths as if they existed inside the public directory.

Is this the intended use case?

File structure:

--dist
----browser.js
--public
----index.html
<html>
<head>
</head>
<body>
  <script type="text/javascript" src="../dist/browser.js"></script>
</body>
</html>

Console output

[Thu Feb 07 2019 08:07:46 GMT-0600 (CST)] "GET /dist/browser.js" Error (404): "Not found"

from http-server.

thornjad avatar thornjad commented on April 28, 2024

@emptyshells that is intended behavior, because the public/ directory is served by default if it exists, and anything outside of that directory is inaccessible to the server. This is for security, since obviously you don't want to serve your entire file system. In this case, it's resolving to an absolute path because the .. "hits" the root directory.

For your specific use case (looks like you're using browserify or something) you could either put browser.js inside the public/ directory somewhere or drop the public/ and put index.html at the same level as dist/.

from http-server.

aderchox avatar aderchox commented on April 28, 2024

I have this issue. I'm referencing a file inside the web root. But yet relative paths in my javascript code don't work and all of them are assumed absolute, starting from the root.

For example:

lib/
    script.js
    test.svg

Now in the script.js if I set imgElement.src = "test.svg"; it becomes a 404 not found (from the error shown in the console), but if I turn the path to lib/test.svg now it works. I've tried with "./test.svg" as well and it doesn't work either.

Any idea why!?

Update: Never mind anymore. It was an issue in my own code. The main script in the root was importing a script in a subdirectory, but the paths used in the subdirectory script were relative, so they resolved relative to root.

from http-server.

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.