Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
Can I use php-cgi to serve an HTML which refers to CSS/JS files from the parent directory?

tl;dr

My understanding is that php -S localhost:1234 -t some-dir serves the page some-dir/index.html at localhost:1234, expecting that CSS and JavaScript (and other files) that the page requires are in some-dir/., not in some-dir/../..

How can I start a server that serves some-dir/index.html and looks for the required files in some-dir/../..

Long version

I have a directory structure like this:

index.html
css
├── some.css
├── style.css
└── sheets.css
docs
├── index.html
└── a lot of other stuff.html
js
├── some.js
├── javascript.js
└── files.js

And obviously anything referred to from within the main index.html is referred via a path containing no ../.

On the other hand, docs/index.html is automatically generated by KSS, a library for documenting CSS modules, and given it position in the tree, when it refers to the very same files as the main index.html, it does so by prepending ../ to the paths. For instance, if the main index.html has

    <script type="text/javascript" src="js/some-script.js"></script>

docs/index.html has

<script src="../js/some-script.js"></script>

Now, for the purpose of debugging JavaScript code launched upon user interactions with docs/index.html, I start the server like this

php -S localhost:1234 -t docs

because docs is the directory where the index.html is, that I want the server to present; but the problem is that the server looks for the files (referenced by the HTML) in the wrong directory, kind of like it strips off ../, so I get errors like the following:

GET http://localhost:1234/css/main.css net::ERR_ABORTED 404 (Not Found)              section-containers.html:12
GET http://localhost:1234/js/swipeable-container.js net::ERR_ABORTED 404 (Not Found) section-containers.html:412 

How can I serve an index.html which uses scripts and stylesheets (are they all together called assets?) from a parent directory?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda