forked from expresscpp/expresscpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserve_favicon.cpp
More file actions
46 lines (36 loc) · 1.13 KB
/
serve_favicon.cpp
File metadata and controls
46 lines (36 loc) · 1.13 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
37
38
39
40
41
42
43
44
45
46
// https://expressjs.com/en/resources/middleware/serve-favicon.html
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "expresscpp/console.hpp"
#include "expresscpp/expresscpp.hpp"
#include "expresscpp/middleware/serve_favicon_provider.hpp"
using namespace expresscpp;
int main() {
ExpressCpp expresscpp;
Console::setLogLevel(LogLevel::kDebug);
FaviconProvider favicon_provider;
expresscpp.Use(favicon_provider);
const uint16_t port = 8081u;
expresscpp.Use([](auto /*req*/, auto res, auto /*next*/) {
if (!res->ResponseSent()) {
res->Send("resource not found");
}
});
// start listening for requests and block until ctrl+C
expresscpp
.Listen(port,
[=](auto ec) {
if (ec) {
std::cerr << "ERROR: " << ec.message() << std::endl;
exit(1);
}
std::cout << "Example app listening on port " << port << std::endl;
std::cout << "go to http://localhost:" << port << "/favicon.ico" << std::endl;
})
.Run();
return 0;
}