Skip to content

Commit

Permalink
Feat: named documents (#17)
Browse files Browse the repository at this point in the history
* chore: deps

* chore: vscode

* feat: named document instead of index

* chore: deps

* feat: cpp defines

* fix: fix
  • Loading branch information
BCsabaEngine authored Aug 13, 2024
1 parent 2404192 commit 07f7e85
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 178 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsserver.experimental.enableProjectDiagnostics": true
}
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ This npm package provides a solution for **inserting any JS client application i
> Starting with version v1.2.0, ESP8266/ESP8285 is also supported.
> Starting with version v1.3.0, c++ defines can be used.
### Usage

**Install package** as devDependency (it is practical if the package is part of the project so that you always receive updates)
Expand Down Expand Up @@ -103,6 +105,11 @@ You can find a minimal buildable example platformio project in [demo/esp32](demo
The content of **generated file** (do not edit, just use)
```c
#define SVELTEESP32_COUNT 5
#define SVELTEESP32_SIZE 145633
#define SVELTEESP32_FILE_index_html
...
const uint8_t data0[12547] = {0x1f, 0x8b, 0x8, 0x0, ...
const uint8_t data1[5368] = {0x1f, 0x8b, 0x8, 0x0, 0x0, ...
const char * etag0 = "387b88e345cc56ef9091...";
Expand Down Expand Up @@ -166,6 +173,34 @@ The use of ETag is **not enabled by default**, this can be achieved with the `--

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.

### C++ defines

To make it easy to integrate into a larger c++ project, we have made a couple of variables available as c++ defines.

You can use the COUNT and SIZE constants:

```c
...
#include "svelteesp32.h"

#if SVELTEESP32_COUNT != 5
#error Invalid file count
#endif
...
```

You can include a warning if a named file accidentally missing from the build:

```c
...
#include "svelteesp32.h"

#ifndef SVELTEESP32_FILE_index_html
#error Missing index file
#endif
...
```

### Command line options

| Option | Required | Description | default |
Expand All @@ -176,6 +211,7 @@ Typically, the entry point for web applications is the **index.htm or index.html
| `--etag` | | Use ETag header for cache | false |
| `--no-gzip` | | Do not compress content with gzip | false -> gzip used |
| `--espmethod` | x | Name of generated method | `initSvelteStaticFiles` |
| `--define` | x | Prefix of c++ defines | `SVELTEESP32` |
| `-h` | | Show help | |

### Q&A
Expand Down
82 changes: 45 additions & 37 deletions demo/esp32/include/svelteesp32async.h

Large diffs are not rendered by default.

60 changes: 34 additions & 26 deletions demo/esp32/include/svelteesp32psychic.h

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions demo/esp32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
#include <ESPAsyncWebServer.h>
#include "svelteesp32async.h"

#if SVELTEESP32_COUNT != 5
#error Invalid file count
#endif

#ifndef SVELTEESP32_FILE_index_html
#error Missing index file
#endif

AsyncWebServer server(80);
void setup()
{
Expand All @@ -18,6 +26,14 @@ void loop() {}
#include <PsychicHttp.h>
#include "svelteesp32psychic.h"

#if SVELTEESP32_COUNT != 5
#error Invalid file count
#endif

#ifndef SVELTEESP32_FILE_index_html
#error Missing index file
#endif

PsychicHttpServer server;
void setup()
{
Expand Down
Loading

0 comments on commit 07f7e85

Please sign in to comment.