BCsabaEngine / svelteesp32

Convert Svelte (or React/Angular/Vue) JS application to serve it from ESP32/ESP8266 webserver
43 stars 6 forks source link

Get reference to default / index file handler #13

Closed kaigoh closed 2 months ago

kaigoh commented 2 months ago

Hi,

First off, amazing work - thank you - you saved some hair pulling dealing with SPIFFS limitations!

To get SvelteKit routing working properly, I need a way of "rewriting" requests to index.html. Is there any way you could extend the C++ output so I can somehow get a reference to the index file handler? The point being I can just do request->send(indexFile) in my server.onNotFound handler.

Or if you have any better ideas?

Thanks :)

BCsabaEngine commented 2 months ago

If your dist folder contains any index.htm or html, the default handler (/) will handle it. So you can access website without index.htm postfix in url.

This handler is not exposed, but in next few days I will look forward to implement this.

BCsabaEngine commented 2 months ago

If I understand correctly, you should serve not existing routes (eg. /asdf/dummy) with index.htm?

kaigoh commented 2 months ago

I've added a pull request (https://github.com/BCsabaEngine/svelteesp32/pull/15) that gives a predictable name to anything related to the default document. It now works nicely with SvelteKit routing :)

BCsabaEngine commented 2 months ago

Thank you for your first contribution! I have merged and released v1.2.7. (I have made some newline correnction to see routes clearly in header file).

Please check it in your project with v1.2.7 and close issue it you are satisfied!

kaigoh commented 2 months ago

Latest version works really nicely :)

BCsabaEngine commented 1 month ago

Sorry, but next 1.3.x version will change with breaking change. I have decided to change to every datat member to named datafield, like this: data_index_html, not only the default. With this you can enforce the existing of needed files.

Example:

data_assets_index_B4xhKHXE_css
etag_assets_index_B4xhKHXE_css
...
data_index_html
etag_index_html
...

You must change the reference from defaultDocument to data_index_html or data_index_htm.

kaigoh commented 1 month ago

Seems a sensible approach - predictable naming all round can only be a good thing 👍

-------- Original Message -------- On 11/08/2024 22:14, Csaba Balázs wrote:

Sorry, but next 1.3.x version will change with breaking change. I have decided to change to every datat member to named datafield, like this: data_index_html, not only the default. With this you can enforce the existing of needed files.

Example:

data_assets_index_B4xhKHXE_css etag_assets_index_B4xhKHXE_css ... data_index_html etag_index_html ...

You must change the reference from defaultDocument to data_index_html or data_index_htm.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you modified the open/close state.Message ID: @.***>

BCsabaEngine commented 1 month ago

We have released v1.3 with some c++ defines too... https://github.com/BCsabaEngine/svelteesp32/releases/tag/v1.3.0