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

Pipe multiple CLI apps to generate a website #427

Open
blueray453 opened this issue Jun 24, 2022 · 0 comments
Open

Pipe multiple CLI apps to generate a website #427

blueray453 opened this issue Jun 24, 2022 · 0 comments

Comments

@blueray453
Copy link

blueray453 commented Jun 24, 2022

Problem Description:

I am working on a solution to pipe multiple CLI apps to generate a website.

In Linux terms, it will look like:

Request | CLI_APP --output json | ADD_UI --output web | ADD_HTTP_RESPONSE_MESSAGE > Response

I am using --output json with CLI_APP to say that the CLI_APP will output json (for REST API).

Here, --output web with ADD_UI will add HTML, CSS, JS etc. to the JSON output.

I am using ADD_HTTP_RESPONSE_MESSAGE to add HEADERS, response code etc. This is because, I want the CLI apps to be totally independent. I do not want to add HTTP response message to CLI_APP or ADD_UI output so that I can reuse these tools in case I decide to make a GUI app or mobile app or something later where HTTP is not involved.

Question:

I think websocketd is the solution of my problem. am I right? Or am i missing something?

In your example codes you did not print any HTTP header or status code, so I assume you deal with the http stuff, and we just print to stdout. I mean, I will not need ADD_HTTP_RESPONSE_MESSAGE. Will it be a correct statement?

In your examples, I did not find how to deal with GET or POST requests. In CGI, we use QUERY_STRING to get data from GET request and then parse it. For, POST, the data is sent as input stream to the program. since the server passes information to this program as an input stream, it sets the environment variable CONTENT_LENGTH to the size of the data in number of bytes (or characters). We can use this to read exactly that much data from standard input. How to deal with GET and POST request in websocketd.

In the count example, there is count.html. It calls ./count.sh via var ws = new WebSocket('ws://localhost:8080/');. So, first we are getting the HTML file, it is calling the sh file. But I want to first hit ./count.sh and it will generate the count.html file. Is it possible?

How to pipe multiple commands to get the output. For example, how can I get the output of ps -ef | grep root | wc -l using websocketd?

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

1 participant