webui-dev / webui

Use any web browser or WebView as GUI, with your preferred language in the backend and modern web technologies in the frontend, all in a lightweight portable library.
https://webui.me
MIT License
2.95k stars 172 forks source link

How to make only the the server running? (Do not create browser window) #330

Closed bin-san closed 7 months ago

bin-san commented 7 months ago

How can I make a webserver using webui, without using the native window? I mean the program will run the server locally, then I have to access it via web browser. I dont want to create native window... Is it possible?

AlbertShown commented 7 months ago

I guess, yes, using NoBrowser.

https://github.com/webui-dev/webui/blob/2a5f0c98fbb267a5aed921a8678f3f108bb12a6e/include/webui.h#L111

AlbertShown commented 7 months ago

webui_show_browser(myWindow, "<html>...</html>", NoBrowser);

bin-san commented 7 months ago
#include <webui.hpp>

int main() {

    webui::window myWindow;
    myWindow.show_browser(
        "<html><script src=\"webui.js\"></script> Hello World from C++! </html>", 
        NoBrowser);
    webui::wait();
    return 0;
}

But now How can I know which port it is running on?

fibodevy commented 7 months ago

Use webui_get_url(), it returns HOST:PORT.

 myWindow.get_url();
bin-san commented 7 months ago

Thank you.