фикс: не использовался путь для статических файлов + немного поменял цвета
This commit is contained in:
parent
1a80e9d455
commit
1536914888
12
src/main.cpp
12
src/main.cpp
@ -121,12 +121,12 @@ public:
|
|||||||
api->startDaemon();
|
api->startDaemon();
|
||||||
auth.users.emplace_back(std::make_shared<http::auth::User>("admin", "", http::auth::User::SUPERUSER));
|
auth.users.emplace_back(std::make_shared<http::auth::User>("admin", "", http::auth::User::SUPERUSER));
|
||||||
|
|
||||||
sf->registerFile(staticFilesPath + FAVICON_ICO, mime_types::image_png, true);
|
sf->registerFile(staticFilesPath + FAVICON_ICO, FAVICON_ICO, mime_types::image_png, true);
|
||||||
sf->registerFile(staticFilesPath + VUE_JS, mime_types::javascript, true);
|
sf->registerFile(staticFilesPath + VUE_JS, VUE_JS, mime_types::javascript, true);
|
||||||
sf->registerFile(staticFilesPath + STYLE_CSS, mime_types::text_css, true);
|
sf->registerFile(staticFilesPath + STYLE_CSS, STYLE_CSS, mime_types::text_css, true);
|
||||||
sf->registerFile(staticFilesPath + FIELDS_CSS, mime_types::text_css, true);
|
sf->registerFile(staticFilesPath + FIELDS_CSS, FIELDS_CSS, mime_types::text_css, true);
|
||||||
sf->registerFile(staticFilesPath + INDEX_HTML, mime_types::text_html, false);
|
sf->registerFile(staticFilesPath + INDEX_HTML, INDEX_HTML, mime_types::text_html, false);
|
||||||
sf->registerFile(staticFilesPath + LOGIN_HTML, mime_types::text_html, true);
|
sf->registerFile(staticFilesPath + LOGIN_HTML, LOGIN_HTML, mime_types::text_html, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerResources(http::server::Server& s) {
|
void registerResources(http::server::Server& s) {
|
||||||
|
@ -22,13 +22,18 @@ static void loadFile(const std::string& path, std::vector<char>& content) {
|
|||||||
|
|
||||||
http::resource::BasicResource::BasicResource(std::string path): path(std::move(path)) {}
|
http::resource::BasicResource::BasicResource(std::string path): path(std::move(path)) {}
|
||||||
|
|
||||||
http::resource::StaticFileFactory::StaticFileDef::StaticFileDef(std::string path, server::mime_types::Mime type, bool allowCache): path(std::move(path)), type(type), allowCache(allowCache) {
|
http::resource::StaticFileFactory::StaticFileDef::StaticFileDef(const std::string& path, std::string webPath, server::mime_types::Mime type, bool allowCache):
|
||||||
|
webPath(std::move(webPath)),
|
||||||
|
#ifdef USE_DEBUG
|
||||||
|
fsPath(path),
|
||||||
|
#endif
|
||||||
|
type(type), allowCache(allowCache) {
|
||||||
#ifdef USE_DEBUG
|
#ifdef USE_DEBUG
|
||||||
if (allowCache) {
|
if (allowCache) {
|
||||||
BOOST_LOG_TRIVIAL(info) << "Load static file " << this->path;
|
BOOST_LOG_TRIVIAL(info) << "Load static file " << this->webPath;
|
||||||
loadFile(this->path, this->content);
|
loadFile(path, this->content);
|
||||||
} else {
|
} else {
|
||||||
BOOST_LOG_TRIVIAL(info) << "Skip loading static file " << this->path;
|
BOOST_LOG_TRIVIAL(info) << "Skip loading static file " << this->webPath;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
BOOST_LOG_TRIVIAL(info) << "Load static file " << this->path;
|
BOOST_LOG_TRIVIAL(info) << "Load static file " << this->path;
|
||||||
@ -39,20 +44,20 @@ http::resource::StaticFileFactory::StaticFileDef::~StaticFileDef() = default;
|
|||||||
|
|
||||||
http::resource::StaticFileFactory::StaticFileFactory() = default;
|
http::resource::StaticFileFactory::StaticFileFactory() = default;
|
||||||
|
|
||||||
void http::resource::StaticFileFactory::registerFile(const std::string &path, server::mime_types::Mime type, bool allowCache) {
|
void http::resource::StaticFileFactory::registerFile(const std::string &path, const std::string &webPath, server::mime_types::Mime type, bool allowCache) {
|
||||||
this->files.emplace_back(path, type, allowCache);
|
this->files.emplace_back(path, webPath, type, allowCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
void http::resource::StaticFileFactory::serve(const std::string &path, server::Reply &rep) {
|
void http::resource::StaticFileFactory::serve(const std::string &path, server::Reply &rep) {
|
||||||
for (auto& f: this->files) {
|
for (auto& f: this->files) {
|
||||||
if (f.path == path) {
|
if (f.webPath == path) {
|
||||||
#ifdef USE_DEBUG
|
#ifdef USE_DEBUG
|
||||||
if (f.allowCache) {
|
if (f.allowCache) {
|
||||||
rep.content.clear();
|
rep.content.clear();
|
||||||
rep.content.insert(rep.content.end(), f.content.begin(), f.content.end());
|
rep.content.insert(rep.content.end(), f.content.begin(), f.content.end());
|
||||||
} else {
|
} else {
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Reload file " << path << " (http path: " << path << ")";
|
BOOST_LOG_TRIVIAL(debug) << "Reload file " << path << " (http path: " << path << ")";
|
||||||
loadFile(f.path, rep.content);
|
loadFile(f.fsPath, rep.content);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
rep.content.clear();
|
rep.content.clear();
|
||||||
|
@ -23,9 +23,12 @@ namespace http::resource {
|
|||||||
class StaticFileFactory {
|
class StaticFileFactory {
|
||||||
class StaticFileDef {
|
class StaticFileDef {
|
||||||
public:
|
public:
|
||||||
StaticFileDef(std::string path, server::mime_types::Mime type, bool allowCache = true);
|
StaticFileDef(const std::string& path, std::string webPath, server::mime_types::Mime type, bool allowCache = true);
|
||||||
|
|
||||||
std::string path;
|
std::string webPath;
|
||||||
|
#ifdef USE_DEBUG
|
||||||
|
std::string fsPath;
|
||||||
|
#endif
|
||||||
server::mime_types::Mime type;
|
server::mime_types::Mime type;
|
||||||
bool allowCache;
|
bool allowCache;
|
||||||
std::vector<char> content;
|
std::vector<char> content;
|
||||||
@ -36,7 +39,7 @@ namespace http::resource {
|
|||||||
public:
|
public:
|
||||||
StaticFileFactory();
|
StaticFileFactory();
|
||||||
|
|
||||||
void registerFile(const std::string& path, server::mime_types::Mime type, bool allowCache = true);
|
void registerFile(const std::string& path, const std::string &webPath, server::mime_types::Mime type, bool allowCache = true);
|
||||||
|
|
||||||
void serve(const std::string& path, server::Reply& rep);
|
void serve(const std::string& path, server::Reply& rep);
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ body {
|
|||||||
--bg-color: #FEFEFE;
|
--bg-color: #FEFEFE;
|
||||||
--bg-selected: #F1F1F1;
|
--bg-selected: #F1F1F1;
|
||||||
--bg-element: #a7a7a7;
|
--bg-element: #a7a7a7;
|
||||||
--bg-action: #5181fe;
|
--bg-action: #81a7ff;
|
||||||
--bg-danger: #db2828;
|
--bg-danger: #ff6464;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user