|
22 | 22 | * Server Constructor |
23 | 23 | * Initialize state and server variables |
24 | 24 | * |
25 | | - * @param vhost Name of the primary Host the HTTP server will respond to |
| 25 | + * @param vhost_aliases List of hostnames the HTTP server will respond to |
26 | 26 | * @param port Port the vhost listens on |
27 | 27 | * @param diskpath Path to the folder the vhost serves up |
28 | 28 | */ |
29 | | -HTTPServer::HTTPServer(std::string vhost, int port, std::string diskpath) { |
| 29 | +HTTPServer::HTTPServer(std::vector<std::string> vhost_aliases, int port, std::string diskpath) { |
30 | 30 | canRun = false; |
31 | 31 | listenSocket = INVALID_SOCKET; |
32 | 32 | listenPort = port; |
33 | 33 |
|
34 | | - // TODO: Eventually we should allow the config to specify multiple vhosts with their own diskpaths |
35 | | - printf("Primary vhost: %s, port: %i, disk path: %s\n", vhost.c_str(), port, diskpath.c_str()); |
| 34 | + printf("Primary port: %i, disk path: %s\n", port, diskpath.c_str()); |
36 | 35 |
|
37 | 36 | // Create a resource host serving the base path ./htdocs on disk |
38 | 37 | ResourceHost* resHost = new ResourceHost(diskpath); |
39 | 38 | hostList.push_back(resHost); |
40 | 39 |
|
41 | | - // Setup the resource host serving htdocs to provide for the following vhosts |
42 | | - // Use the primary vhost to also serve up localhost/127.0.0.1 (which is why we only added one ResourceHost to hostList above) |
| 40 | + // Always serve up localhost/127.0.0.1 (which is why we only added one ResourceHost to hostList above) |
43 | 41 | char tmpstr[32]; |
44 | 42 | sprintf(tmpstr, "localhost:%i", listenPort); |
45 | 43 | vhosts.insert(std::pair<std::string, ResourceHost*>(std::string(tmpstr).c_str(), resHost)); |
46 | 44 | sprintf(tmpstr, "127.0.0.1:%i", listenPort); |
47 | 45 | vhosts.insert(std::pair<std::string, ResourceHost*>(std::string(tmpstr).c_str(), resHost)); |
48 | | - sprintf(tmpstr, "%s:%i", vhost.c_str(), listenPort); |
49 | | - vhosts.insert(std::pair<std::string, ResourceHost*>(std::string(tmpstr).c_str(), resHost)); |
| 46 | + |
| 47 | + // Setup the resource host serving htdocs to provide for the vhost aliases |
| 48 | + for (std::string vh : vhost_aliases) { |
| 49 | + printf("vhost: %s\n", vh.c_str()); |
| 50 | + sprintf(tmpstr, "%s:%i", vh.c_str(), listenPort); |
| 51 | + vhosts.insert(std::pair<std::string, ResourceHost*>(std::string(tmpstr).c_str(), resHost)); |
| 52 | + } |
50 | 53 | } |
51 | 54 |
|
52 | 55 | /** |
|
0 commit comments