|
| 1 | +#include <iostream> |
| 2 | + |
1 | 3 | #include "devserver/httplib/httplib.h" |
2 | 4 | #include "tools/cpp/runfiles/runfiles.h" |
3 | 5 |
|
4 | 6 | using bazel::tools::cpp::runfiles::Runfiles; |
5 | 7 |
|
| 8 | +constexpr char kWorkspaceName[] = "rules_devserver"; |
| 9 | +constexpr char kDefaultPort[] = "8080"; |
| 10 | + |
6 | 11 | int main(int argc, char **argv) { |
7 | 12 | httplib::Server svr; |
8 | | - std::string port = "8080"; |
| 13 | + std::string port = std::string(kDefaultPort); |
| 14 | + std::string static_file; |
9 | 15 |
|
10 | 16 | std::string runfiles_error; |
11 | 17 | std::unique_ptr<Runfiles> runfiles( |
12 | 18 | Runfiles::Create(argv[0], BAZEL_CURRENT_REPOSITORY, &runfiles_error)); |
13 | 19 |
|
14 | | - std::string path = runfiles->Rlocation("devserver/"); |
| 20 | + std::string path = runfiles->Rlocation("rules_devserver/"); |
15 | 21 | std::cout << "path: " << path << std::endl; |
16 | 22 |
|
17 | | - // print all args |
18 | 23 | for (int i = 0; i < argc; i++) { |
19 | 24 | std::cout << "argv[" << i << "] = " << argv[i] << std::endl; |
20 | | - } |
21 | 25 |
|
22 | | - for (int i = 0; i < argc; i++) { |
23 | 26 | if (std::string(argv[i]).rfind("--port", 0) != std::string::npos) { |
24 | 27 | port = std::string(argv[i]).substr(7); |
25 | 28 | } |
| 29 | + |
| 30 | + if (std::string(argv[i]).rfind("--static_file", 0) != std::string::npos) { |
| 31 | + static_file = std::string(argv[i]).substr(14); |
| 32 | + } |
26 | 33 | } |
27 | 34 |
|
| 35 | + std::cout << "static_file:" << static_file << std::endl; |
| 36 | + |
28 | 37 | svr.Get("/", [](const httplib::Request &req, httplib::Response &res) { |
29 | 38 | res.set_content("Hello World!", "text/html"); |
30 | 39 | }); |
|
0 commit comments