MCPcopy Create free account
hub / github.com/chronoxor/CppServer / main

Function main

examples/http_server.cpp:190–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188};
189
190int main(int argc, char** argv)
191{
192 // HTTP server port
193 int port = 8080;
194 if (argc > 1)
195 port = std::atoi(argv[1]);
196 // HTTP server content path
197 std::string www = "../www/api";
198 if (argc > 2)
199 www = argv[2];
200
201 std::cout << "HTTP server port: " << port << std::endl;
202 std::cout << "HTTP server static content path: " << www << std::endl;
203 std::cout << "HTTP server website: " << "http://localhost:" << port << "/api/index.html" << std::endl;
204
205 std::cout << std::endl;
206
207 // Create a new Asio service
208 auto service = std::make_shared<AsioService>();
209
210 // Start the Asio service
211 std::cout << "Asio service starting...";
212 service->Start();
213 std::cout << "Done!" << std::endl;
214
215 // Create a new HTTP server
216 auto server = std::make_shared<HTTPCacheServer>(service, port);
217 server->AddStaticContent(www, "/api");
218
219 // Start the server
220 std::cout << "Server starting...";
221 server->Start();
222 std::cout << "Done!" << std::endl;
223
224 std::cout << "Press Enter to stop the server or '!' to restart the server..." << std::endl;
225
226 // Perform text input
227 std::string line;
228 while (getline(std::cin, line))
229 {
230 if (line.empty())
231 break;
232
233 // Restart the server
234 if (line == "!")
235 {
236 std::cout << "Server restarting...";
237 server->Restart();
238 std::cout << "Done!" << std::endl;
239 continue;
240 }
241 }
242
243 // Stop the server
244 std::cout << "Server stopping...";
245 server->Stop();
246 std::cout << "Done!" << std::endl;
247

Callers

nothing calls this directly

Calls 5

StartMethod · 0.45
AddStaticContentMethod · 0.45
emptyMethod · 0.45
RestartMethod · 0.45
StopMethod · 0.45

Tested by

no test coverage detected