Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag to render raw view instead of HTML #97

Open
dsgibbons opened this issue Mar 7, 2024 · 4 comments
Open

Flag to render raw view instead of HTML #97

dsgibbons opened this issue Mar 7, 2024 · 4 comments

Comments

@dsgibbons
Copy link

dsgibbons commented Mar 7, 2024

Say I have a local filesystem with

.
├── a.yaml
├── b.yaml
└── c
    └── d.yaml

Running curl localhost:5000 currently outputs something like:

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="generator" content="github.com/patrickdappollonio/http-server 2.1.4">
  <meta name="theme-color" content="#3f51b5">
  <title>HTTP File Server</title>
  <link rel="stylesheet" href="/_/h6y23gab/assets/style.css">
  <link rel="stylesheet" href="/_/h6y23gab/assets/roboto-font.css">
  <link rel="stylesheet" href="/_/h6y23gab/assets/fontawesome-6.2.0.css">
  <link rel="icon" type="image/svg+xml" href="/_/h6y23gab/assets/file-server.svg">
  <link rel="stylesheet" href="/_/h6y23gab/assets/gfm.css">
</head>


<body>

<header>
  <div class="container">
    <nav>
      <a class="page-title" href="/">HTTP File Server</a>
      <ul>
        <li>
          <a href="https://github.com/patrickdappollonio/http-server" rel="noopener" target="_blank"><i class="fab fa-github"></i> Github Repo</a>
        </li>
        <li>
          <a href="https://ghcr.io/patrickdappollonio/docker-http-server" rel="noopener" target="_blank"><i class="fab fa-docker"></i> Container Image</a>
        </li>
      </ul>
    </nav>
  </div>
</header>


<section id="directory-listing">
  <div class="container">

    <div class="card-large">
      <ul class="files">
        <li>
          <span class="files-heading">
            <span class="name"><strong>Name</strong></span>
            <span class="size"><strong>Size</strong></span>
            <span class="date"><strong>Modified</strong></span>
          </span>
        </li>
        <li class="file">
          <a href="/c/" data-name="c">
            <span class="name"><i class="fas fa-folder"></i> c</span>
            <span class="size">-</span>
            <span class="date">Mar 7, 2024 5:48am UTC</span>
          </a>
        </li>
        <li class="file">
          <a href="/a.yaml" data-name="a.yaml">
            <span class="name"><i class="fas fa-code"></i> a.yaml</span>
            <span class="size">0B</span>
            <span class="date">Mar 7, 2024 5:48am UTC</span>
          </a>
        </li>
        <li class="file">
          <a href="/b.yaml" data-name="b.yaml">
            <span class="name"><i class="fas fa-code"></i> b.yaml</span>
            <span class="size">0B</span>
            <span class="date">Mar 7, 2024 5:48am UTC</span>
          </a>
        </li>
      </ul>
    </div>
  </div>
</section>


<footer>
  <div class="container">
    <p>
      Powered by <a href="https://github.com/patrickdappollonio/http-server" target="_blank" rel="noopener"><code>http-server</code></a>
      by <a href="https://www.patrickdap.com/?ref=http-server" target="_blank" rel="noopener">Patrick D'appollonio</a>.
      Icons by <a href="https://fontawesome.com/" target="_blank" rel="nofollow noopener">FontAwesome</a>.
    </p>
  </div>
</footer>


<script src="/_/h6y23gab/assets/code.js"></script>
</body>
</html>

If I use a script to interact with http-server, I need to parse this HTML. Can there be an option like --list-raw or --disable-html, where:

curl localhost:5000

would yield

c/
a.yaml
b.yaml

and

curl localhost:5000/c/

would yield

d.yaml
@patrickdappollonio
Copy link
Owner

Hey! Sounds like an interesting idea, so basically you just want the file listing part, with the files being simply text, is that correct?

I like the idea, what I'm not sure is if there are any drawbacks, if you could share your use case (besides what you shared above) that could help me figure things out!

Let me know!

@dsgibbons
Copy link
Author

dsgibbons commented Mar 7, 2024

I'm writing data pipelines using Dagster. I trigger certain behaviour based on configuration files that are uploaded to an HTTP server. I don't want anything too complicated (which is what drew me to this project). I currently use a bit of Python to parse the HTML and locate the files, but I'd rather just have the option of stripping out as much HTML as possible. A simple / after a name is enough to indicate that there is a folder that can be listed by appending it to the current URL. I don't need the full path of each file to be printed as I can work it out from the URL.

@patrickdappollonio
Copy link
Owner

Hey @dsgibbons!

Thinking more about this, I think it could be possible if we introduce querystring parameters, so something like:

http://localhost:5000/?text-only=true
http://localhost:5000/a-folder/?text-only=true

Would render this text version of the list. It would only work in folders, and for files will hold no effect.
Seems like it could be easy to implement like that. Changing the default behaviour, even with a flag or something like that seems off to me and to a handful of people that are active users of this repository/app.

Let me know if something like that would work for you and I can start thinking about its implementation!

@dsgibbons
Copy link
Author

Hi @patrickdappollonio, that sounds OK to me! Thank you for considering my proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants