static int scriptAliasDirective(MaState *state, cchar *key, cchar *value) { HttpRoute *route; char *prefix, *path; if (!maTokenize(state, value, "%S %S", &prefix, &path)) { return MPR_ERR_BAD_SYNTAX; } route = httpCreateAliasRoute(state->route, prefix, path, 0); httpSetRouteHandler(route, "cgiHandler"); httpSetRoutePattern(route, sfmt("^%s(.*)$", prefix), 0); httpSetRouteTarget(route, "run", "$1"); httpFinalizeRoute(route); return 0; }
/* Configure the server. If the configFile is defined, use it. If not, then consider home, documents, ip and port. */ int maConfigureServer(MaServer *server, cchar *configFile, cchar *home, cchar *documents, cchar *ip, int port) { MaAppweb *appweb; Http *http; HttpEndpoint *endpoint; HttpHost *host; HttpRoute *route; char *path; appweb = server->appweb; http = appweb->http; if (configFile) { path = mprGetAbsPath(configFile); if (maParseConfig(server, path, 0) < 0) { /* mprUserError("Can't configure server using %s", path); */ return MPR_ERR_CANT_INITIALIZE; } return 0; } else { mprLog(2, "DocumentRoot %s", documents); if ((endpoint = httpCreateConfiguredEndpoint(home, documents, ip, port)) == 0) { return MPR_ERR_CANT_OPEN; } maAddEndpoint(server, endpoint); host = mprGetFirstItem(endpoint->hosts); mprAssert(host); route = mprGetFirstItem(host->routes); mprAssert(route); #if UNUSED searchPath = getSearchPath(dir); mprSetModuleSearchPath(searchPath); #endif #if BLD_FEATURE_CGI maLoadModule(appweb, "cgiHandler", "mod_cgi"); if (httpLookupStage(http, "cgiHandler")) { httpAddRouteHandler(route, "cgiHandler", "cgi cgi-nph bat cmd pl py"); /* Add cgi-bin with a route for the /cgi-bin URL prefix. */ path = "cgi-bin"; if (mprPathExists(path, X_OK)) { HttpRoute *cgiRoute; cgiRoute = httpCreateAliasRoute(route, "/cgi-bin/", path, 0); mprLog(4, "ScriptAlias \"/cgi-bin/\":\"%s\"", path); httpSetRouteHandler(cgiRoute, "cgiHandler"); httpFinalizeRoute(cgiRoute); } } #endif #if BLD_FEATURE_ESP maLoadModule(appweb, "espHandler", "mod_esp"); if (httpLookupStage(http, "espHandler")) { httpAddRouteHandler(route, "espHandler", "esp"); } #endif #if BLD_FEATURE_EJSCRIPT maLoadModule(appweb, "ejsHandler", "mod_ejs"); if (httpLookupStage(http, "ejsHandler")) { httpAddRouteHandler(route, "ejsHandler", "ejs"); } #endif #if BLD_FEATURE_PHP maLoadModule(appweb, "phpHandler", "mod_php"); if (httpLookupStage(http, "phpHandler")) { httpAddRouteHandler(route, "phpHandler", "php"); } #endif httpAddRouteHandler(route, "fileHandler", ""); httpFinalizeRoute(route); } if (home) { maSetServerHome(server, home); } if (ip || port > 0) { maSetServerAddress(server, ip, port); } return 0; }