繁体   English   中英

如何在 EC2 实例上部署我的 REST API

[英]How do I deploy my REST API on an EC2 Instance

我在 EC2 实例上部署我的 REST api 时遇到了一些问题。

具体来说,在我的代码中,我执行以下操作:

server.setEndpoint("http://ec2-18-135-114-10.eu-west-2.compute.amazonaws.com:6502");

调用 function(cpprestsdk 的包装器):

void BasicController::setEndpoint(const std::string & value) {
        uri endpointURI(value);
        uri_builder endpointBuilder;

        endpointBuilder.set_scheme(endpointURI.scheme());
        if (endpointURI.host() == "host_auto_ip4") {
            endpointBuilder.set_host(NetworkUtils::hostIP4());        
        }
        else if (endpointURI.host() == "host_auto_ip6") {
            endpointBuilder.set_host(NetworkUtils::hostIP6());
        }
        endpointBuilder.set_port(endpointURI.port());
        endpointBuilder.set_path(endpointURI.path());

        listener = http_listener(endpointBuilder.to_uri());
    }

但是,我收到异常“URI 必须包含主机名”

好的,所以我使用弹性公共 IPv4 地址再次尝试:

server.setEndpoint("http://18.135.114.10:6502/");

同样,我得到同样的错误 - 没有主机名。

我唯一可以工作的情况是在本地主机上,看起来像

server.setEndpoint("http://127.0.1.1:6502:6502/");

注意,这个文件显示了异常是如何从 cpprestsdk 库https://github.com/microsoft/cpprestsdk/blob/master/Release/src/http/client/http_client.cpp

这可能是一个非常愚蠢的问题,所以我感谢一个善良的人给予他们的帮助

解决办法,把function改成:

void BasicController::setEndpoint(const std::string & value) {
        uri endpointURI(value);
        uri_builder endpointBuilder;

        endpointBuilder.set_scheme(endpointURI.scheme());
        if (endpointURI.host() == "host_auto_ip4") {
            endpointBuilder.set_host(NetworkUtils::hostIP4());        
        }
        else if (endpointURI.host() == "host_auto_ip6") {
            endpointBuilder.set_host(NetworkUtils::hostIP6());
        }
        else {
            endpointBuilder.set_host(endpointURI.host());
        } 
        endpointBuilder.set_port(endpointURI.port());
        endpointBuilder.set_path(endpointURI.path());

        listener = http_listener(endpointBuilder.to_uri());
    }

并使用

server.setEndpoint("http://ec2-18-135-114-10.eu-west2.compute.amazonaws.com:6502/");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM