static int createEndpoints(int argc, char **argv) { HttpHost *host; HttpRoute *route; host = httpCreateHost(); httpSetDefaultHost(host); route = httpCreateRoute(host); httpSetHostDefaultRoute(host, route); httpFinalizeRoute(route); httpInitConfig(route); if (httpLoadConfig(route, app->configFile) < 0) { return MPR_ERR_CANT_CREATE; } mprGC(MPR_GC_FORCE | MPR_GC_COMPLETE); return 0; }
/* Convenience function to create and configure a new endpoint without using a config file. */ HttpEndpoint *httpCreateConfiguredEndpoint(cchar *home, cchar *documents, cchar *ip, int port) { Http *http; HttpHost *host; HttpEndpoint *endpoint; HttpRoute *route; http = MPR->httpService; if (ip == 0) { /* If no IP:PORT specified, find the first endpoint */ if ((endpoint = mprGetFirstItem(http->endpoints)) != 0) { ip = endpoint->ip; port = endpoint->port; } else { ip = "localhost"; if (port <= 0) { port = HTTP_DEFAULT_PORT; } if ((endpoint = httpCreateEndpoint(ip, port, NULL)) == 0) { return 0; } } } else { if ((endpoint = httpCreateEndpoint(ip, port, NULL)) == 0) { return 0; } } if ((host = httpCreateHost(home)) == 0) { return 0; } if ((route = httpCreateRoute(host)) == 0) { return 0; } httpSetHostDefaultRoute(host, route); httpSetHostIpAddr(host, ip, port); httpAddHostToEndpoint(endpoint, host); httpSetRouteDir(route, documents); httpFinalizeRoute(route); return endpoint; }
/* Create a new server. A server may manage may multiple servers and virtual hosts. If ip/port endpoint is supplied, this call will create a Server on that endpoint. Otherwise, maConfigureServer should be called later. A default route is created with the document root set to "." */ PUBLIC MaServer *maCreateServer(MaAppweb *appweb, cchar *name) { MaServer *server; HttpHost *host; HttpRoute *route; assert(appweb); if ((server = mprAllocObj(MaServer, manageServer)) == NULL) { return 0; } if (name == 0 || *name == '\0') { name = "default"; } server->name = sclone(name); server->endpoints = mprCreateList(-1, 0); server->limits = httpCreateLimits(1); server->appweb = appweb; server->http = appweb->http; server->defaultHost = host = httpCreateHost(NULL); if (!httpGetDefaultHost()) { httpSetDefaultHost(host); } route = httpCreateRoute(host); httpSetRouteName(route, "default"); //UNUSED httpSetRoutePrefix(route, ""); httpSetHostDefaultRoute(host, route); route->limits = server->limits; maAddServer(appweb, server); if (appweb->defaultServer == 0) { maSetDefaultServer(appweb, server); } return server; }