svelteesp32 1.6.1 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/commandLine.d.ts +1 -0
- package/dist/commandLine.js +5 -0
- package/dist/cppCode.js +31 -0
- package/dist/index.js +2 -2
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@ In order to be able to easily update OTA, it is important - from the users' poin
|
|
|
12
12
|
|
|
13
13
|
This npm package provides a solution for **inserting any JS client application into the ESP web server** (PsychicHttp and also ESPAsyncWebServer available, PsychicHttp is the default). For this, JS, html, css, font, assets, etc. files must be converted to binary byte array. Npm mode is easy to use and easy to **integrate into your CI/CD pipeline**.
|
|
14
14
|
|
|
15
|
+
> Starting with version v1.7.0, with the cachetime command line option, you can set whether the browser can cache pages
|
|
16
|
+
|
|
15
17
|
> Starting with version v1.6.0, mime npm package is used instead of mime-types (application/javascript -> text/javascript)
|
|
16
18
|
|
|
17
19
|
> Starting with version v1.5.0, PsychicHttp v2 is also supported.
|
|
@@ -176,6 +178,12 @@ The use of ETag is **not enabled by default**, this can be achieved with the `--
|
|
|
176
178
|
|
|
177
179
|
> This setting has three states: yes, no, and compiler mode is available. In compiler mode, you can disable/enable ETag by setting the `SVELTEESP32_ENABLE_ETAG` c++ compiler directive. For example, if using platformio, just type `-D SVELTEESP32_ENABLE_ETAG`.
|
|
178
180
|
|
|
181
|
+
### Cache-control
|
|
182
|
+
|
|
183
|
+
By default (when using the ETag), we send no-cache in the cache-control header of the HTTP response. Pages, subpages and other elements are downloaded every time. This is perfectly acceptable when serving small pages with ESP.
|
|
184
|
+
|
|
185
|
+
At the same time, it can be an advantage that the content is cached by the browser and not even the ETag check is performed. For this, you can specify how many seconds the max-age value sent instead of no-cache should be. In the case of `--cachetime=86400` (max-age=86400), the page (and other elements) will not be downloaded by the browser **for one day**.
|
|
186
|
+
|
|
179
187
|
### Main entry point - index.html
|
|
180
188
|
|
|
181
189
|
Typically, the entry point for web applications is the **index.htm or index.html** file. This does not need to be listed in the browser's address bar because web servers know that this file should be served by default. Svelteesp32 also does this: if there is an index.htm or index.html file, it sets it as the main file to be served. So using `http://esp_xxx.local` or just entering the `http://x.y.w.z/` IP address will serve this main file.
|
|
@@ -230,6 +238,7 @@ You can use the following c++ directives at the project level if you want to con
|
|
|
230
238
|
| `-e` | The engine for which the include file is created (psychic/psychic2/async) | psychic |
|
|
231
239
|
| `-o` | Generated output file with path | `svelteesp32.h` |
|
|
232
240
|
| `--etag` | Use ETag header for cache (true/false/compiler) | false |
|
|
241
|
+
| `--cachetime` | Override no-cache response with a max-age=<cachetime> response | 0 |
|
|
233
242
|
| `--gzip` | Compress content with gzip (true/false/compiler) | true |
|
|
234
243
|
| `--created` | Include creation time | false |
|
|
235
244
|
| `--version` | Include a version string, `--version=v$npm_package_version` | '' |
|
package/dist/commandLine.d.ts
CHANGED
package/dist/commandLine.js
CHANGED
|
@@ -75,6 +75,11 @@ exports.cmdLine = (0, ts_command_line_args_1.parse)({
|
|
|
75
75
|
description: 'Prefix of c++ defines',
|
|
76
76
|
defaultValue: 'SVELTEESP32'
|
|
77
77
|
},
|
|
78
|
+
cachetime: {
|
|
79
|
+
type: Number,
|
|
80
|
+
description: 'max-age cache time in seconds',
|
|
81
|
+
defaultValue: 0
|
|
82
|
+
},
|
|
78
83
|
help: { type: Boolean, optional: true, alias: 'h', description: 'Shows this help' }
|
|
79
84
|
}, {
|
|
80
85
|
helpArg: 'help',
|
package/dist/cppCode.js
CHANGED
|
@@ -151,12 +151,22 @@ void {{methodName}}(PsychicHttpServer * server) {
|
|
|
151
151
|
|
|
152
152
|
{{#switch ../etag}}
|
|
153
153
|
{{#case "true"}}
|
|
154
|
+
{{#../cacheTime}}
|
|
155
|
+
response.addHeader("cache-control", "max-age={{value}}");
|
|
156
|
+
{{/../cacheTime}}
|
|
157
|
+
{{^../cacheTime}}
|
|
154
158
|
response.addHeader("cache-control", "no-cache");
|
|
159
|
+
{{/../cacheTime}}
|
|
155
160
|
response.addHeader("ETag", etag_{{this.dataname}});
|
|
156
161
|
{{/case}}
|
|
157
162
|
{{#case "compiler"}}
|
|
158
163
|
#ifdef {{../definePrefix}}_ENABLE_ETAG
|
|
164
|
+
{{#../cacheTime}}
|
|
165
|
+
response.addHeader("cache-control", "max-age={{value}}");
|
|
166
|
+
{{/../cacheTime}}
|
|
167
|
+
{{^../cacheTime}}
|
|
159
168
|
response.addHeader("cache-control", "no-cache");
|
|
169
|
+
{{/../cacheTime}}
|
|
160
170
|
response.addHeader("ETag", etag_{{this.dataname}});
|
|
161
171
|
#endif
|
|
162
172
|
{{/case}}
|
|
@@ -327,12 +337,22 @@ void {{methodName}}(PsychicHttpServer * server) {
|
|
|
327
337
|
|
|
328
338
|
{{#switch ../etag}}
|
|
329
339
|
{{#case "true"}}
|
|
340
|
+
{{#../cacheTime}}
|
|
341
|
+
response->addHeader("cache-control", "max-age={{value}}");
|
|
342
|
+
{{/../cacheTime}}
|
|
343
|
+
{{^../cacheTime}}
|
|
330
344
|
response->addHeader("cache-control", "no-cache");
|
|
345
|
+
{{/../cacheTime}}
|
|
331
346
|
response->addHeader("ETag", etag_{{this.dataname}});
|
|
332
347
|
{{/case}}
|
|
333
348
|
{{#case "compiler"}}
|
|
334
349
|
#ifdef {{../definePrefix}}_ENABLE_ETAG
|
|
350
|
+
{{#../cacheTime}}
|
|
351
|
+
response->addHeader("cache-control", "max-age={{value}}");
|
|
352
|
+
{{/../cacheTime}}
|
|
353
|
+
{{^../cacheTime}}
|
|
335
354
|
response->addHeader("cache-control", "no-cache");
|
|
355
|
+
{{/../cacheTime}}
|
|
336
356
|
response->addHeader("ETag", etag_{{this.dataname}});
|
|
337
357
|
#endif
|
|
338
358
|
{{/case}}
|
|
@@ -507,12 +527,22 @@ void {{methodName}}(AsyncWebServer * server) {
|
|
|
507
527
|
|
|
508
528
|
{{#switch ../etag}}
|
|
509
529
|
{{#case "true"}}
|
|
530
|
+
{{#../cacheTime}}
|
|
531
|
+
response->addHeader("cache-control", "max-age={{value}}");
|
|
532
|
+
{{/../cacheTime}}
|
|
533
|
+
{{^../cacheTime}}
|
|
510
534
|
response->addHeader("cache-control", "no-cache");
|
|
535
|
+
{{/../cacheTime}}
|
|
511
536
|
response->addHeader("ETag", etag_{{this.dataname}});
|
|
512
537
|
{{/case}}
|
|
513
538
|
{{#case "compiler"}}
|
|
514
539
|
#ifdef {{../definePrefix}}_ENABLE_ETAG
|
|
540
|
+
{{#../cacheTime}}
|
|
541
|
+
response->addHeader("cache-control", "max-age={{value}}");
|
|
542
|
+
{{/../cacheTime}}
|
|
543
|
+
{{^../cacheTime}}
|
|
515
544
|
response->addHeader("cache-control", "no-cache");
|
|
545
|
+
{{/../cacheTime}}
|
|
516
546
|
response->addHeader("ETag", etag_{{this.dataname}});
|
|
517
547
|
#endif
|
|
518
548
|
{{/case}}
|
|
@@ -548,6 +578,7 @@ const getCppCode = (sources, filesByExtension) => (0, handlebars_1.compile)(comm
|
|
|
548
578
|
created: commandLine_1.cmdLine.created,
|
|
549
579
|
version: commandLine_1.cmdLine.version,
|
|
550
580
|
methodName: commandLine_1.cmdLine.espmethod,
|
|
581
|
+
cacheTime: commandLine_1.cmdLine.cachetime ? { value: commandLine_1.cmdLine.cachetime } : undefined,
|
|
551
582
|
definePrefix: commandLine_1.cmdLine.define
|
|
552
583
|
}, {
|
|
553
584
|
helpers: {
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const node_crypto_1 = require("node:crypto");
|
|
|
7
7
|
const node_fs_1 = require("node:fs");
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const node_zlib_1 = require("node:zlib");
|
|
10
|
-
const
|
|
10
|
+
const mime_types_1 = require("mime-types");
|
|
11
11
|
const commandLine_1 = require("./commandLine");
|
|
12
12
|
const consoleColor_1 = require("./consoleColor");
|
|
13
13
|
const cppCode_1 = require("./cppCode");
|
|
@@ -29,7 +29,7 @@ console.log();
|
|
|
29
29
|
console.log('Translation to header file');
|
|
30
30
|
const longestFilename = [...files.keys()].reduce((p, c) => Math.max(c.length, p), 0);
|
|
31
31
|
for (const [originalFilename, content] of files) {
|
|
32
|
-
const mimeType =
|
|
32
|
+
const mimeType = (0, mime_types_1.lookup)(originalFilename) || 'text/plain';
|
|
33
33
|
summary.filecount++;
|
|
34
34
|
const filename = originalFilename.replace(/\\/g, '/');
|
|
35
35
|
const dataname = filename.replace(/[!&()+./@{}~-]/g, '_');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelteesp32",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Convert Svelte (or any frontend) JS application to serve it from ESP32 webserver (PsychicHttp)",
|
|
5
5
|
"author": "BCsabaEngine",
|
|
6
6
|
"license": "ISC",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/BCsabaEngine/svelteesp32",
|
|
30
30
|
"scripts": {
|
|
31
|
-
"dev:async": "nodemon src/index.ts -- -e async -s ./demo/svelte/dist -o ./demo/esp32/include/svelteesp32.h --etag=true --gzip=true --version=v$npm_package_version",
|
|
31
|
+
"dev:async": "nodemon src/index.ts -- -e async -s ./demo/svelte/dist -o ./demo/esp32/include/svelteesp32.h --etag=true --gzip=true --cachetime=86400 --version=v$npm_package_version",
|
|
32
32
|
"dev:psychic": "nodemon src/index.ts -- -e psychic -s ./demo/svelte/dist -o ./demo/esp32/include/svelteesp32.h --etag=false --gzip=false --version=v$npm_package_version",
|
|
33
33
|
"dev:psychic2": "nodemon src/index.ts -- -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/svelteesp32.h --etag=false --gzip=false --version=v$npm_package_version",
|
|
34
34
|
"test:all": "./package.script && ~/.platformio/penv/bin/pio run -d ./demo/esp32",
|
|
@@ -54,23 +54,24 @@
|
|
|
54
54
|
"espasyncwebserver"
|
|
55
55
|
],
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@types/
|
|
58
|
-
"@
|
|
59
|
-
"@typescript-eslint/
|
|
60
|
-
"eslint": "^
|
|
61
|
-
"eslint
|
|
57
|
+
"@types/mime-types": "^2.1.4",
|
|
58
|
+
"@types/node": "^22.10.10",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^8.21.0",
|
|
60
|
+
"@typescript-eslint/parser": "^8.21.0",
|
|
61
|
+
"eslint": "^9.19.0",
|
|
62
|
+
"eslint-config-prettier": "^10.0.1",
|
|
62
63
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
63
64
|
"eslint-plugin-unicorn": "^56.0.1",
|
|
64
|
-
"nodemon": "^3.1.
|
|
65
|
+
"nodemon": "^3.1.9",
|
|
65
66
|
"prettier": "^3.4.2",
|
|
66
67
|
"ts-node": "^10.9.2",
|
|
67
68
|
"tsx": "^4.19.2",
|
|
68
|
-
"typescript": "^5.7.
|
|
69
|
+
"typescript": "^5.7.3"
|
|
69
70
|
},
|
|
70
71
|
"dependencies": {
|
|
71
|
-
"glob": "^11.0.
|
|
72
|
+
"glob": "^11.0.1",
|
|
72
73
|
"handlebars": "^4.7.8",
|
|
73
|
-
"mime": "^
|
|
74
|
+
"mime-types": "^2.1.35",
|
|
74
75
|
"ts-command-line-args": "^2.5.1"
|
|
75
76
|
}
|
|
76
77
|
}
|