/* Create a simple stand-alone web server */ int main(int argc, char **argv, char **envp) { Mpr *mpr; int rc; rc = MPR_ERR_CANT_CREATE; if ((mpr = mprCreate(0, NULL, MPR_USER_EVENTS_THREAD)) == 0) { mprError("Cannot create runtime"); return -1; } if (httpCreate(HTTP_CLIENT_SIDE | HTTP_SERVER_SIDE) == 0) { mprError("Cannot create the HTTP services"); return -1; } mprStart(); if (maParseConfig("appweb.conf") < 0) { mprError("Cannot parse the config file %s", "appweb.conf"); return -1; } httpDefineAction("/action/myaction", myaction); if (httpStartEndpoints() < 0) { mprError("Cannot start the web server"); return -1; } mprServiceEvents(-1, 0); mprDestroy(); return 0; }
/* Create a simple stand-alone web server */ int main(int argc, char **argv, char **envp) { Mpr *mpr; MaAppweb *appweb; MaServer *server; int rc; rc = MPR_ERR_CANT_CREATE; if ((mpr = mprCreate(0, NULL, MPR_USER_EVENTS_THREAD)) == 0) { mprError("Cannot create the web server runtime"); return -1; } mprStart(); appweb = maCreateAppweb(mpr); mprAddRoot(appweb); server = maCreateServer(appweb, 0); if (maParseConfig(server, "appweb.conf", 0) < 0) { mprError("Cannot parse the config file %s", "appweb.conf"); return -1; } httpDefineAction("/action/myaction", myaction); if (maStartServer(server) < 0) { mprError("Cannot start the web server"); return -1; } mprServiceEvents(-1, 0); maStopServer(server); mprRemoveRoot(appweb); mprDestroy(MPR_EXIT_DEFAULT); return 0; }
static HttpRoute *createLoginRoute(HttpRoute *route, cchar *pattern, HttpAction action) { bool secure; secure = 0; if (sstarts(pattern, "https:///")) { pattern = &pattern[8]; secure = 1; } else if (sstarts(pattern, "http:///")) { pattern = &pattern[7]; } if ((route = httpCreateInheritedRoute(route)) != 0) { httpSetRoutePattern(route, sjoin("^", pattern, "$", NULL), 0); if (secure) { httpAddRouteCondition(route, "secure", "https://", HTTP_ROUTE_REDIRECT); } if (action) { route->handler = route->http->actionHandler; httpDefineAction(pattern, action); } httpFinalizeRoute(route); } return route; }