Closed iliazeus closed 6 months ago
Why not create a directory with the single file you want to serve?
@kugland the same reason I don't just spin up nginx instead: it's way less convenient.
I have this use case as well. I just need to serve a single HTML page on localhost, which I request using window.open()
on Chromium, then I register a ServiceWorker
from a script in the HTML which is used to stream data to the Tab which opened the window
. I don't even need darkhttpd
to remain active once the single request is served. I can use Native Messaging to start the local server, ideally the server would terminate itself once the request is served - the script and ServiceWorker
in the served HTML will remain active.
I can kinda appreciate this from a simplicity and security standpoint - locking serving down to a single path. Who wants to implement it?
I am not an expert in C. Otherwise I would file a PR as this is exactly what I am looking for for my own projects in the browser and potentially as a base to import into QuickJS.
I couldn't keep myself from trying to implement this. Here is my naive approach: https://github.com/g-rden/darkhttpd/commit/134f8258c888fbf3c4a3b8850aae122aca65683a
I am not sure what --chroot should do. Should it error, change to the directory the file is in or something else? Probably the second, but it could get quite annoying to get the directory name and the file name without the path.
I couldn't keep myself from trying to implement this. Here is my naive approach: g-rden@134f825
I am not sure what --chroot should do. Should it error, change to the directory the file is in or something else? Probably the second, but it could get quite annoying to get the directory name and the file name without the path.
You could open the file and keep the file handle, and then chroot to an empty directory.
https://github.com/g-rden/darkhttpd/commit/b83124b449a30ec2a5cbd78b749d64bd71da8165 this implements the second option for --chroot. I think this makes the most sense.
Nice work @g-rden, please open a PR!
Often, I want to just share a single file over HTTP. Right now, we can only pass a directory to
darkhttpd
, and it will serve any file from that directory. I would love to be able to dodarkhttpd ./my/single/file.html
.