svelteesp32
Version:
Convert Svelte (or any frontend) JS application to serve it from ESP32 webserver (PsychicHttp)
191 lines (171 loc) • 4.64 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.espidfTemplate = void 0;
exports.espidfTemplate = `
//engine: espidf
//cmdline: {{{commandLine}}}
{{
//created: {{now}}
{{/if}}
//
{{
{{
{{/case}}
{{
{{/case}}
{{/switch}}
{{
{{
{{/case}}
{{
{{/case}}
{{/switch}}
//
{{
{{/if}}
//
{{
{{/each}}
//
{{
{{/each}}
//
{{
{{
{{
const char datagzip_{{this.dataname}}[{{this.lengthGzip}}] = { {{this.bytesGzip}} };
{{/each}}
{{/case}}
{{
{{
const char data_{{this.dataname}}[{{this.length}}] = { {{this.bytes}} };
{{/each}}
{{/case}}
{{
{{
const char datagzip_{{this.dataname}}[{{this.lengthGzip}}] = { {{this.bytesGzip}} };
{{/each}}
{{
const char data_{{this.dataname}}[{{this.length}}] = { {{this.bytes}} };
{{/each}}
{{/case}}
{{/switch}}
//
{{
{{
{{
const char * etag_{{this.dataname}} = "{{this.md5}}";
{{/each}}
{{/case}}
{{
{{/case}}
{{
{{
const char * etag_{{this.dataname}} = "{{this.md5}}";
{{/each}}
{{/case}}
{{/switch}}
{{
static esp_err_t file_handler_{{this.datanameUpperCase}} (httpd_req_t *req)
{
httpd_resp_set_type(req, "{{this.mime}}");
{{
{{
{{
httpd_resp_set_hdr(req, "Content-Encoding", "gzip");
{{/if}}
{{/case}}
{{
{{
httpd_resp_set_hdr(req, "Content-Encoding", "gzip");
{{/if}}
{{/case}}
{{/switch}}
{{
{{
{{#../cacheTime}}
httpd_resp_set_hdr(req, "Cache-Control", "max-age={{value}}");
{{/../cacheTime}}
{{^../cacheTime}}
httpd_resp_set_hdr(req, "Cache-Control", "no-cache");
{{/../cacheTime}}
httpd_resp_set_hdr(req, "ETag", etag_{{this.dataname}});
{{/case}}
{{
{{#../cacheTime}}
httpd_resp_set_hdr(req, "Cache-Control", "max-age={{value}}");
{{/../cacheTime}}
{{^../cacheTime}}
httpd_resp_set_hdr(req, "Cache-Control", "no-cache");
{{/../cacheTime}}
httpd_resp_set_hdr(req, "ETag", etag_{{this.dataname}});
{{/case}}
{{/switch}}
{{
{{
httpd_resp_send(req, datagzip_{{this.dataname}}, {{this.lengthGzip}});
{{/case}}
{{
httpd_resp_send(req, data_{{this.dataname}}, {{this.length}});
{{/case}}
{{
httpd_resp_send(req, datagzip_{{this.dataname}}, {{this.lengthGzip}});
httpd_resp_send(req, data_{{this.dataname}}, {{this.length}});
{{/case}}
{{/switch}}
return ESP_OK;
}
{{
static const httpd_uri_t route_def_{{this.datanameUpperCase}} = {
.uri = "/",
.method = HTTP_GET,
.handler = file_handler_{{this.datanameUpperCase}},
};
{{/if}}
static const httpd_uri_t route_{{this.datanameUpperCase}} = {
.uri = "/{{this.filename}}",
.method = HTTP_GET,
.handler = file_handler_{{this.datanameUpperCase}},
};
{{/each}}
static inline void {{methodName}}(httpd_handle_t server) {
{{
{{
httpd_register_uri_handler(server, &route_def_{{this.datanameUpperCase}});
{{/if}}
httpd_register_uri_handler(server, &route_{{this.datanameUpperCase}});
{{/each}}
}`;