fix: Resolve req paths correctly in Admin WebApp
This commit is contained in:
1 parent
ce9880a9b1
commit
0107d934e5
3 files changed
+45
-23
No files matched your search
@@ -4,8 +4,8 @@
|
||||
<title>BTS Spark Admin</title>
|
||||
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="shortcut icon" type="image/ico" href="img/favicon.ico" />
|
||||
<link rel="stylesheet" href="font-awesome.min.css" />
|
||||
<link rel="shortcut icon" type="image/ico" href="public/img/favicon.ico" />
|
||||
<link rel="stylesheet" href="public/font-awesome.min.css" />
|
||||
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=es6"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -52,7 +52,7 @@ let update msg model =
|
||||
// View
|
||||
|
||||
let root model dispatch =
|
||||
let sparkImg = "img/BTS-300.png"
|
||||
let sparkImg = "public/img/BTS-300.png"
|
||||
let handler msg (ev:Browser.Types.Event) =
|
||||
!!ev.target?value |> msg |> dispatch
|
||||
section [ ClassName "hero is-fullheight is-primary" ] [
|
||||
|
||||
@@ -47,6 +47,10 @@ std::string read_file(const std::string &path) {
|
||||
namespace bts {
|
||||
namespace http {
|
||||
|
||||
using Path = boost::filesystem::path;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
struct ServerState {
|
||||
std::mutex _m;
|
||||
utils::Dispatcher &_dispatcher;
|
||||
@@ -124,6 +128,8 @@ struct ServerState {
|
||||
if (iter != _session.end()) {
|
||||
GatewayRequest request;
|
||||
if (request.ParseFromString(msg->get_payload())) {
|
||||
LOG(Http, Info, "WebServer::on_message. req: {}",
|
||||
request.DebugString());
|
||||
iter->second.handle(
|
||||
request, [this, hdl](const GatewayResponse &response) {
|
||||
websocketpp::lib::error_code ec;
|
||||
@@ -299,39 +305,55 @@ struct ServerState {
|
||||
con->set_body(body);
|
||||
}
|
||||
|
||||
boost::filesystem::path web_ui_path(const boost::filesystem::path &root) {
|
||||
auto reldir = root / "web/ui";
|
||||
if (boost::filesystem::exists(reldir))
|
||||
return reldir;
|
||||
reldir = root / "ui";
|
||||
Path admin_web_app_path(const Path &root) {
|
||||
const auto reldir = root / "Spark.Admin.WebApp";
|
||||
if (boost::filesystem::exists(reldir))
|
||||
return reldir;
|
||||
if (root.has_parent_path())
|
||||
return web_ui_path(root.parent_path());
|
||||
return admin_web_app_path(root.parent_path());
|
||||
return _www;
|
||||
}
|
||||
|
||||
boost::filesystem::path map_path_to_filesystem(const std::string &resource) {
|
||||
std::string config = "/config";
|
||||
std::string files = "/files";
|
||||
std::string perf_trace = "/perf_trace";
|
||||
std::string docs = "/docs";
|
||||
Path map_path_to_filesystem(const std::string &resource) {
|
||||
vector<string> index_aliases{"/", "/index", "/index.html"};
|
||||
const string fonts{"/fonts"};
|
||||
const std::string config{"/config"};
|
||||
const std::string files{"/files"};
|
||||
const std::string perf_trace{"/perf_trace"};
|
||||
const std::string docs{"/docs"};
|
||||
|
||||
if (resource.compare(0, config.size(), config) == 0) {
|
||||
return _conf + resource.substr(config.size());
|
||||
} else if (resource.compare(0, files.size(), files) == 0) {
|
||||
return _www + resource.substr(files.size());
|
||||
} else if (resource.compare(0, perf_trace.size(), perf_trace) == 0) {
|
||||
return os::sparkd_wd() + "/data_files" + resource;
|
||||
} else if (resource.compare(0, docs.size(), docs) == 0) {
|
||||
return os::sparkd_wd() + "/web" + resource;
|
||||
#define STARTS_WITH(y) ((resource.compare(0, y.size(), y)) == 0)
|
||||
|
||||
if (std::find(index_aliases.begin(), index_aliases.end(), resource) !=
|
||||
index_aliases.end()) {
|
||||
return Path{admin_web_app_path(os::get_install_path())} / "public" /
|
||||
"index.html";
|
||||
}
|
||||
return web_ui_path(os::get_install_path()) / resource;
|
||||
if (STARTS_WITH(fonts)) {
|
||||
return Path{admin_web_app_path(os::get_install_path())} / "public" /
|
||||
resource;
|
||||
}
|
||||
if (STARTS_WITH(config)) {
|
||||
return _conf + resource.substr(config.size());
|
||||
}
|
||||
if (STARTS_WITH(files)) {
|
||||
return _www + resource.substr(files.size());
|
||||
}
|
||||
if (STARTS_WITH(perf_trace)) {
|
||||
return Path{os::sparkd_wd()} / "data_files" / resource;
|
||||
}
|
||||
if (STARTS_WITH(docs)) {
|
||||
return Path{os::sparkd_wd()} / "Spark.Admin.WebApp" / resource;
|
||||
}
|
||||
return admin_web_app_path(os::get_install_path()) / resource;
|
||||
|
||||
#undef STARTS_WITH
|
||||
}
|
||||
|
||||
void return_file(connection_ptr &con, const boost::filesystem::path &path) {
|
||||
con->set_body(read_file(path.string()));
|
||||
con->set_status(websocketpp::http::status_code::ok);
|
||||
LOG(Http, Info, "WebServer::return_file. path: {}", path);
|
||||
}
|
||||
|
||||
void return_bts_installer(connection_ptr &con) {
|
||||
|
||||
Reference in new issue
Block a user