Untie dash.c from packed fs

This commit is contained in:
cpq
2026-05-03 08:40:24 +01:00
parent c9f89166f4
commit 5a2e42ae25
5 changed files with 12 additions and 10 deletions
+1 -1
View File
@@ -121,6 +121,7 @@ fail:
#endif
#define MG_NO_CACHE_HEADERS "Cache-Control: no-cache\r\n"
#define MG_JSON_HEADERS "Content-Type: application/json\r\n" MG_NO_CACHE_HEADERS
@@ -574,7 +575,6 @@ void mg_dash_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
struct mg_http_serve_opts opts;
memset(&opts, 0, sizeof(opts));
opts.fs = &mg_fs_packed;
mg_mem_files = mg_packed_files;
mg_http_serve_file(c, hm, "/dashboard.html", &opts);
} else {
struct mg_dash_custom_handler *ch = dash->custom_handlers;
+1 -1
View File
@@ -1,4 +1,5 @@
#include "dash.h"
#include "util.h"
#define MG_NO_CACHE_HEADERS "Cache-Control: no-cache\r\n"
#define MG_JSON_HEADERS "Content-Type: application/json\r\n" MG_NO_CACHE_HEADERS
@@ -453,7 +454,6 @@ void mg_dash_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
struct mg_http_serve_opts opts;
memset(&opts, 0, sizeof(opts));
opts.fs = &mg_fs_packed;
mg_mem_files = mg_packed_files;
mg_http_serve_file(c, hm, "/dashboard.html", &opts);
} else {
struct mg_dash_custom_handler *ch = dash->custom_handlers;
@@ -43,7 +43,7 @@ static const unsigned char v1[] = {
101, 61, 34, 109, 111, 100, 117, 108, 101, 34, 32, 115, // e="module" s
114, 99, 61, 34, 109, 97, 105, 110, 46, 106, 115, 34, // rc="main.js"
62, 60, 47, 115, 99, 114, 105, 112, 116, 62, 10, 60, // ></script>.<
47, 104, 116, 109, 108, 62, 10,// /html>.
47, 104, 116, 109, 108, 62, 10, 0 // /html>.
};
static const unsigned char v2[] = {
39, 117, 115, 101, 32, 115, 116, 114, 105, 99, 116, 39, // 'use strict'
@@ -269,7 +269,7 @@ static const unsigned char v2[] = {
108, 111, 97, 100, 32, 61, 32, 40, 41, 32, 61, 62, // load = () =>
32, 114, 101, 110, 100, 101, 114, 40, 104, 40, 65, 112, // render(h(Ap
112, 41, 44, 32, 100, 111, 99, 117, 109, 101, 110, 116, // p), document
46, 98, 111, 100, 121, 41, 59, 10,// .body);.
46, 98, 111, 100, 121, 41, 59, 10, 0 // .body);.
};
static const unsigned char v3[] = {
118, 97, 114, 32, 101, 44, 110, 44, 95, 44, 116, 44, // var e,n,_,t,
@@ -1371,7 +1371,7 @@ static const unsigned char v3[] = {
97, 115, 32, 117, 115, 101, 68, 101, 98, 117, 103, 86, // as useDebugV
97, 108, 117, 101, 44, 95, 101, 32, 97, 115, 32, 117, // alue,_e as u
115, 101, 69, 114, 114, 111, 114, 66, 111, 117, 110, 100, // seErrorBound
97, 114, 121, 125, 59, 10,// ary};.
97, 114, 121, 125, 59, 10, 0 // ary};.
};
static const unsigned char v4[] = {
42, 32, 123, 32, 98, 111, 120, 45, 115, 105, 122, 105, // * { box-sizi
@@ -1526,14 +1526,14 @@ static const unsigned char v4[] = {
100, 116, 104, 58, 32, 57, 50, 48, 112, 120, 41, 32, // dth: 920px)
123, 32, 46, 114, 111, 119, 32, 46, 99, 111, 108, 32, // { .row .col
123, 32, 119, 105, 100, 116, 104, 58, 32, 49, 48, 48, // { width: 100
37, 59, 32, 125, 32, 125, 10,// %; } }.
37, 59, 32, 125, 32, 125, 10, 0 // %; } }.
};
const struct mg_mem_file mg_packed_files[] = {
{"/web_root/index.html", v1, sizeof(v1), 1730991857},
{"/web_root/main.js", v2, sizeof(v2), 1730991857},
{"/web_root/preact.min.js", v3, sizeof(v3), 1730991857},
{"/web_root/style.css", v4, sizeof(v4), 1730991857},
{"/web_root/index.html", v1, sizeof(v1) - 1, 1730991857},
{"/web_root/main.js", v2, sizeof(v2) - 1, 1730991857},
{"/web_root/preact.min.js", v3, sizeof(v3) - 1, 1730991857},
{"/web_root/style.css", v4, sizeof(v4) - 1, 1730991857},
{NULL, NULL, 0, 0}
};
@@ -190,6 +190,7 @@ void mg_dash_init(struct mg_mgr *mgr) {
// Require authentication
dash.authenticate = authenticate;
mg_mem_files = mg_packed_files;
mg_http_listen(mgr, MG_HTTP_ADDR, mg_dash_ev_handler, &dash);
}
@@ -38,6 +38,7 @@ static struct mg_field_set field_set_status = {
void mg_dash_init(struct mg_mgr *mgr) {
static struct mg_dash dash; // Important: keep it static!
MG_DASH_ADD_FIELD_SET(&dash, &field_set_status);
mg_mem_files = mg_packed_files;
mg_http_listen(mgr, MG_HTTP_ADDR, mg_dash_ev_handler, &dash);
}