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

display webpage of directory listing #216

Open
timbo100 opened this issue Apr 18, 2024 · 1 comment
Open

display webpage of directory listing #216

timbo100 opened this issue Apr 18, 2024 · 1 comment

Comments

@timbo100
Copy link

Hi someone else on my team has been responsible for build our application that uses Restinio and it's all working well.
However, I need to figure out how to be able to allow users to navigate and view the directory contents of on our system.
The directory is .../public/logs/, which will contain numerous *.csv files.

Please help or offer direction on where to get help. Thanks

ps My next questions will be how to I get the name of a selected file from that webpage, or how can I influence how the HTML code is rendered for each file so that when selected the page navigates to a new route that will open the file or render a new page?

Thanks again.

@eao197
Copy link
Member

eao197 commented Apr 19, 2024

Hi!

RESTinio doesn't provide a functionality to return a list of files in a directory as a HTML page. You have to serve public/logs path by yourself (it may be simpler if you are using express-based router). When you get a HTTP GET request for public/logs you collect a list of files (by using std::filesystem::directory_iterator for example), then you make a HTML page and return it in the response body. Each name in that HTML file will be represented as a reference (something like <a href="https://yoursite/public/logs/some-file.csv">some-file.csv</a>). When a user clicks on that reference in a browser you will get a new HTTP GET request with public/logs/some-file.csv as the target. Then you can handle this request by reading the content of some-file.csv and sending this content back as the response (or you can use sendfile functionality).

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

No branches or pull requests

2 participants