фикс: не использовался путь для статических файлов
This commit is contained in:
parent
e2618e0300
commit
1a80e9d455
36
src/main.cpp
36
src/main.cpp
@ -104,31 +104,29 @@ class ServerResources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr const char* INDEX_HTML = "static/main.html";
|
static constexpr const char* INDEX_HTML = "/main.html";
|
||||||
static constexpr const char* LOGIN_HTML = "static/login.html";
|
static constexpr const char* LOGIN_HTML = "/login.html";
|
||||||
|
|
||||||
// картинки, их даже можно кешировать
|
// картинки, их даже можно кешировать
|
||||||
static constexpr const char* FAVICON_ICO = "static/favicon.png";
|
static constexpr const char* FAVICON_ICO = "/favicon.png";
|
||||||
static constexpr const char* VUE_JS = "static/js/vue.js"; // это тоже можно кешировать
|
static constexpr const char* VUE_JS = "/js/vue.js"; // это тоже можно кешировать
|
||||||
|
|
||||||
// а эти стили нельзя кешировать в отладочной версии
|
// а эти стили нельзя кешировать в отладочной версии
|
||||||
static constexpr const char* STYLE_CSS = "static/style.css";
|
static constexpr const char* STYLE_CSS = "/style.css";
|
||||||
static constexpr const char* FIELDS_CSS = "static/fields.css";
|
static constexpr const char* FIELDS_CSS = "/fields.css";
|
||||||
|
|
||||||
ServerResources(const ServerResources&) = delete;
|
ServerResources(const ServerResources&) = delete;
|
||||||
|
|
||||||
ServerResources(): sf(std::make_unique<http::resource::StaticFileFactory>()), api(std::make_unique<api_driver::ApiDriver>()) {
|
ServerResources(const std::string& staticFilesPath): sf(std::make_unique<http::resource::StaticFileFactory>()), api(std::make_unique<api_driver::ApiDriver>()) {
|
||||||
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(FAVICON_ICO, mime_types::image_png, true);
|
sf->registerFile(staticFilesPath + FAVICON_ICO, mime_types::image_png, true);
|
||||||
sf->registerFile(VUE_JS, mime_types::javascript, true);
|
sf->registerFile(staticFilesPath + VUE_JS, mime_types::javascript, true);
|
||||||
|
sf->registerFile(staticFilesPath + STYLE_CSS, mime_types::text_css, true);
|
||||||
sf->registerFile(STYLE_CSS, mime_types::text_css, true);
|
sf->registerFile(staticFilesPath + FIELDS_CSS, mime_types::text_css, true);
|
||||||
sf->registerFile(FIELDS_CSS, mime_types::text_css, true);
|
sf->registerFile(staticFilesPath + INDEX_HTML, mime_types::text_html, false);
|
||||||
|
sf->registerFile(staticFilesPath + LOGIN_HTML, mime_types::text_html, true);
|
||||||
sf->registerFile(INDEX_HTML, mime_types::text_html, false);
|
|
||||||
sf->registerFile(LOGIN_HTML, mime_types::text_html, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerResources(http::server::Server& s) {
|
void registerResources(http::server::Server& s) {
|
||||||
@ -473,9 +471,9 @@ int main(int argc, char *argv[]) {
|
|||||||
if (argc != 4 && argc != 5) {
|
if (argc != 4 && argc != 5) {
|
||||||
std::cerr << "Usage: http_server <ssl|nossl> <address> <port> [static files directory]\n";
|
std::cerr << "Usage: http_server <ssl|nossl> <address> <port> [static files directory]\n";
|
||||||
std::cerr << " For IPv4, try:\n";
|
std::cerr << " For IPv4, try:\n";
|
||||||
std::cerr << " receiver nossl 0.0.0.0 80\n";
|
std::cerr << " receiver nossl 0.0.0.0 80 .\n";
|
||||||
std::cerr << " For IPv6, try:\n";
|
std::cerr << " For IPv6, try:\n";
|
||||||
std::cerr << " receiver nossl 0::0 80\n";
|
std::cerr << " receiver nossl 0::0 80 .\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,7 +494,9 @@ int main(int argc, char *argv[]) {
|
|||||||
BOOST_LOG_TRIVIAL(info) << "Generated new secret key " << http::auth::jwt::secretKey;
|
BOOST_LOG_TRIVIAL(info) << "Generated new secret key " << http::auth::jwt::secretKey;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ServerResources resources;
|
const std::string staticFilesPath = (argc == 5 ? argv[4]: ".");
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Use static files path: " << staticFilesPath << "/";
|
||||||
|
ServerResources resources(staticFilesPath);
|
||||||
|
|
||||||
// Initialise the server.
|
// Initialise the server.
|
||||||
std::unique_ptr<http::server::Server> s;
|
std::unique_ptr<http::server::Server> s;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user