-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.cpp
More file actions
36 lines (33 loc) · 1.24 KB
/
main.cpp
File metadata and controls
36 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <string>
#include "../server/server.hpp"
#include "handlers.hpp"
void mapServerPaths(Server& server) {
server.setNotFoundErrPage("static/404.html");
server.get("/", new ShowPage("static/home.html"));
server.get("/home.png", new ShowImage("static/home.png"));
server.get("/rand", new RandomNumberHandler());
server.get("/login", new ShowPage("static/logincss.html"));
server.post("/login", new LoginHandler());
server.get("/up", new ShowPage("static/upload_form.html"));
server.post("/up", new UploadHandler());
server.get("/colors", new ColorHandler("template/colors.html"));
server.get("/music", new ShowPage("static/music.html"));
server.get("/music/moonlight.mp3", new ShowFile("static/moonlight.mp3", "audio/mpeg"));
}
int main(int argc, char** argv) {
try {
int port = argc > 1 ? std::stoi(argv[1]) : 5000;
Server server(port);
mapServerPaths(server);
std::cout << "Server running on port: " << port << std::endl;
server.run();
}
catch (const std::invalid_argument& e) {
std::cerr << e.what() << std::endl;
}
catch (const Server::Exception& e) {
std::cerr << e.getMessage() << std::endl;
}
return 0;
}