Search code examples
c++resthttplistenercasablanca

c++ rest sdk http_listener as a network server


How to configure http_listener to listen on my ip address so other computers on the network can send requests to the server ?

http_listener listener(L"http://localhsot:9000"); // not working
http_listener listener(L"http://0.0.0.0:9000"); // run time error
http_listener listener(L"http://*:9000");       // run time error

I want to use c++ rest sdk as a server on my local network .


Solution

  • https://casablanca.codeplex.com/discussions/478976

    HENRYTM Answer

    Hi I also encountered this problem. You can solve this by using nginx as proxy on linux. This can also add https feature to your server. Here is a small version of the needed nginx config file:

       server {
        listen *:80;
        server_name localhost;
    
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://localhost:12345/;
                proxy_redirect http://localhost:12345/ https://$server_name/;
      }
    

    This script redirects all traffic to 12345. Now you just have to listen to

       http_listener listener(L"http://localhost:12345");
    

    Don't forget to the "support" calls. Cheers, Henry