Skip to content

Commit 6e1adb8

Browse files
committed
0.0.8
1 parent 028dab6 commit 6e1adb8

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

devserver/defs.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ def devserver(name, port, static_files, workspace_name, debug = False, data = []
3636
data = data + [Label("@rules_devserver//devserver:devserver_loader")],
3737
deps = ["@bazel_tools//tools/cpp/runfiles"],
3838
linkopts = ["-lpthread"],
39-
copts = ["-fpermissive"],
39+
copts = ["-fpermissive", "-w"],
4040
)

devserver/main.cc

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ json ComputeManifest(const PathMap &path_to_contents) {
6868
}
6969

7070
std::string GetDevserverLoaderScriptContents(
71-
const std::string &workspace_root) {
72-
const std::string devserver_loader_path =
73-
std::string(kWorkspaceName) + "/devserver/devserver_loader.js";
71+
const std::string &runfiles_root, const std::string &workspace_root) {
72+
const std::string devserver_loader_path = runfiles_root + "/" +
73+
std::string(kWorkspaceName) +
74+
"/devserver/devserver_loader.js";
7475
DEBUG_LOG("devserver_loader_path: " << devserver_loader_path);
7576

7677
std::string devserver_loader_contents;
@@ -136,8 +137,8 @@ PathMap ComputePathMap(const std::string &workspace_root,
136137

137138
Arguments ParseArguments(int argc, char **argv) {
138139
std::string workspace_name = kWorkspaceName;
139-
args::ArgumentParser parser("This is a test program.",
140-
"This goes after the options.");
140+
args::ArgumentParser parser("rules_devserver",
141+
"Bazel web development server.");
141142
args::ValueFlag<int32_t> port(parser, "port", "Server port", {"port"},
142143
kDefaultPort);
143144
args::ValueFlagList<std::string> static_files(
@@ -166,9 +167,7 @@ Arguments ParseArguments(int argc, char **argv) {
166167
DEBUG_LOG("workspace_name: " << workspace_name);
167168
}
168169

169-
const std::vector<std::string> static_files_list(args::get(static_files));
170-
171-
return Arguments{args::get(port), static_files_list, workspace_name};
170+
return Arguments{args::get(port), args::get(static_files), workspace_name};
172171
}
173172

174173
int main(int argc, char **argv) {
@@ -183,7 +182,11 @@ int main(int argc, char **argv) {
183182
const std::vector<std::string> static_files = args.static_files;
184183
const std::string workspace_name = args.workspace_name;
185184

186-
const std::string workspace_root = runfiles->Rlocation(workspace_name + "/");
185+
std::string workspace_root = runfiles->Rlocation(workspace_name);
186+
const std::string runfiles_root =
187+
workspace_root.substr(0, workspace_root.find_last_of("/"));
188+
workspace_root = workspace_root + "/";
189+
DEBUG_LOG("runfiles_root: " << runfiles_root);
187190
DEBUG_LOG("workspace_root: " << workspace_root << "\n\n");
188191

189192
const PathMap path_map = ComputePathMap(workspace_root, static_files);
@@ -202,12 +205,13 @@ int main(int argc, char **argv) {
202205
res.set_content(contents, "text/html");
203206
});
204207
}
205-
svr.Get(
206-
"/devserver/devserver_loader.js",
207-
[&workspace_root](const httplib::Request &req, httplib::Response &res) {
208-
res.set_content(GetDevserverLoaderScriptContents(workspace_root),
209-
"text/javascript");
210-
});
208+
svr.Get("/devserver/devserver_loader.js",
209+
[&runfiles_root, &workspace_root](const httplib::Request &req,
210+
httplib::Response &res) {
211+
res.set_content(
212+
GetDevserverLoaderScriptContents(runfiles_root, workspace_root),
213+
"text/javascript");
214+
});
211215

212216
svr.Get("/devserver/manifest",
213217
[&manifest](const httplib::Request &req, httplib::Response &res) {

examples/single_static_file/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
load("//devserver:defs.bzl", "devserver")
22

3-
43
devserver(
54
name = "serve",
65
port = 8081,

0 commit comments

Comments
 (0)