#Middleware server for website-based app
15 messages · Page 1 of 1 (latest)
You can make a ServiceWorker https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
Is there a replacement for the url devpath/distdir that does the same thing but still allows that custom js to be added?
I guess I could try to find whatever internal module does the browsing stuff and manually implement that but not sure if it's the best approach
What do you mean by replacement for the url devpath/distdir
Well right now I'm just using a url in devpath/distdir in config to load a site
Instead of the usual file path
I'm still not sure what you are trying to accomplish since I have no idea what your project is about
If I had to guess what you wanna do is an app that does my-app https://youtube.com and it'll open the specified website?
Because all you need to do then is in the .setup function retrieve the argument and use a WindowBuilder to create a window with that url
It sounds to me like the question is about whether Tauri can intercept the network requests of an arbitrary page, then modify or drop them?
If that's what it is then a ServiceWorker is the solution, Tauri doesn't have handlers for all network traffic, but a ServiceWorker will catch literally every single piece of networking that happens in the webview and you can decide to do whatever you want with the request
Can a ServiceWorker represent the main content of the page?
Ok so I can just use window builder for the site part, but how do I get the service worker running from there?
Yes
It needs something to initially load it, but once loaded it can do whatever you want (networking related), so if your index.html file loads the worker, then sends a request for another javascript file or something, the service worker can generate that javascript file for you if you want and you essentially have a fully on SSR solution (WASM optional) running entirely within the browser
For external websites it can be tricky and I haven't investigated it too much. I think you just have to eval the relevant javascript into the window for it, but there are limitations on service workers from the webview side that it has to be loaded from the proper origin, and I'm not sure if the eval counts, and it'll struggle for any external sites that provide their own service worker implementations
This is why working with external content is difficult