|
1 | 1 | #include <iostream> |
2 | 2 |
|
3 | | -#include "external/rules_devserver/devserver/argparse/argparse.h" |
4 | | -#include "external/rules_devserver/devserver/httplib/httplib.h" |
| 3 | +// #include "external/rules_devserver/devserver/argparse/argparse.h" |
| 4 | +// #include "external/rules_devserver/devserver/httplib/httplib.h" |
| 5 | + |
| 6 | +#include "devserver/argparse/argparse.h" |
| 7 | +#include "devserver/httplib/httplib.h" |
5 | 8 | #include "tools/cpp/runfiles/runfiles.h" |
6 | 9 |
|
7 | 10 | using bazel::tools::cpp::runfiles::Runfiles; |
@@ -63,20 +66,39 @@ int main(int argc, char **argv) { |
63 | 66 | DEBUG_LOG("package_name: " << args::get(package_name)); |
64 | 67 | } |
65 | 68 |
|
66 | | - const std::string path = runfiles->Rlocation(workspace_name + "/"); |
| 69 | + const std::string workspace_root = runfiles->Rlocation(workspace_name + "/"); |
| 70 | + DEBUG_LOG("workspace_root: " << workspace_root << "\n\n"); |
67 | 71 |
|
68 | 72 | const std::string static_file_path = |
69 | | - path + args::get(package_name) + "/" + args::get(static_file); |
| 73 | + workspace_root + args::get(package_name) + "/" + args::get(static_file); |
70 | 74 | DEBUG_LOG("static_file_path: " << static_file_path); |
71 | 75 |
|
72 | 76 | std::string static_file_contents; |
73 | 77 | static_file_contents = GetFileContents(static_file_path); |
74 | | - DEBUG_LOG("static_file_contents: " << static_file_contents) |
75 | 78 |
|
| 79 | + const std::regex re("<\\/head>"); |
| 80 | + const std::string replacement = |
| 81 | + "<script src=\"/devserver_loader.js\"></script></head>"; |
| 82 | + static_file_contents = |
| 83 | + std::regex_replace(static_file_contents, re, replacement); |
| 84 | + |
| 85 | + DEBUG_LOG("static_file_contents: " << static_file_contents); |
76 | 86 | svr.Get("/", [&static_file_contents](const httplib::Request &req, |
77 | 87 | httplib::Response &res) { |
78 | 88 | res.set_content(static_file_contents, "text/html"); |
79 | 89 | }); |
80 | 90 |
|
| 91 | + svr.Get("/devserver_loader.js", [&workspace_root](const httplib::Request &req, |
| 92 | + httplib::Response &res) { |
| 93 | + const std::string devserver_loader_path = |
| 94 | + workspace_root + "devserver/devserver_loader.js"; |
| 95 | + DEBUG_LOG("devserver_loader_path: " << devserver_loader_path); |
| 96 | + |
| 97 | + std::string devserver_loader_contents; |
| 98 | + devserver_loader_contents = GetFileContents(devserver_loader_path); |
| 99 | + |
| 100 | + res.set_content(devserver_loader_contents, "text/javascript"); |
| 101 | + }); |
| 102 | + |
81 | 103 | svr.listen(kHost, args::get(port)); |
82 | 104 | } |
0 commit comments