1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-24 04:33:49 +01:00

Webserver - include css, js in index (#932)

* add new config options

* init variables in code

* load css and js in python

* update print inside webserver

* fix indentation

* fix indentation

* indentation fix

* fix condition in init

* use cv.file_ instead of cv.string

* do not import EsphomeError

* support embedding js and css at the same time as defined in url

* handle css as separate page

* handle js as separate page

* fix copy and paste error
This commit is contained in:
Elkropac
2020-02-20 13:05:10 +01:00
committed by GitHub
parent 4402a6eb4c
commit 67cbaabd99
4 changed files with 107 additions and 8 deletions

View File

@@ -41,6 +41,12 @@ class WebServer : public Controller, public Component, public AsyncWebHandler {
*/
void set_css_url(const char *css_url);
/** Set local path to the script that's embedded in the index page. Defaults to
*
* @param css_include Local path to web server script.
*/
void set_css_include(const char *css_include);
/** Set the URL to the script that's embedded in the index page. Defaults to
* https://esphome.io/_static/webserver-v1.min.js
*
@@ -48,6 +54,12 @@ class WebServer : public Controller, public Component, public AsyncWebHandler {
*/
void set_js_url(const char *js_url);
/** Set local path to the script that's embedded in the index page. Defaults to
*
* @param js_include Local path to web server script.
*/
void set_js_include(const char *js_include);
// ========== INTERNAL METHODS ==========
// (In most use cases you won't need these)
/// Setup the internal web server and register handlers.
@@ -61,6 +73,16 @@ class WebServer : public Controller, public Component, public AsyncWebHandler {
/// Handle an index request under '/'.
void handle_index_request(AsyncWebServerRequest *request);
#ifdef WEBSERVER_CSS_INCLUDE
/// Handle included css request under '/0.css'.
void handle_css_request(AsyncWebServerRequest *request);
#endif
#ifdef WEBSERVER_JS_INCLUDE
/// Handle included js request under '/0.js'.
void handle_js_request(AsyncWebServerRequest *request);
#endif
bool using_auth() { return username_ != nullptr && password_ != nullptr; }
#ifdef USE_SENSOR
@@ -135,7 +157,9 @@ class WebServer : public Controller, public Component, public AsyncWebHandler {
const char *username_{nullptr};
const char *password_{nullptr};
const char *css_url_{nullptr};
const char *css_include_{nullptr};
const char *js_url_{nullptr};
const char *js_include_{nullptr};
};
} // namespace web_server