Plugin static files

17 views
Skip to first unread message

Владимир Калачихин

unread,
May 1, 2022, 8:05:12 AM5/1/22
to Signal K
"an be webapps as well: a webapp's /public/ directory is mounted under server's root under module id http://yourserver/moduleid"

Ok, but is there any way to do something in the plugin if the file is missing?

Teppo Kurki

unread,
May 2, 2022, 10:19:05 AM5/2/22
to signalk
Webapps are really for client side apps that are just a bunch of static files on the server. Why would the file not be there and what should happen if it is not, as there is nothing on the client side you can do about it?

Or are you actually talking about handlers for custom http paths?

If you need to do anything more complex I suggest you use registerWithRouter, I just added documentation for it at https://github.com/SignalK/signalk-server/blob/master/SERVERPLUGINS.md#exposing-custom-http-paths. Then you can do more complex stuff. This is better than using Express directly, as your plugin stuff gets mounted under a plugin specific prefix. Then you can add a public/index.html that redirects to the /plugins/<pluginId>/xxx where your app actually lives so that the user can navigate from Admin UI Webapps to your app.


--
You received this message because you are subscribed to the Google Groups "Signal K" group.
To unsubscribe from this group and stop receiving emails from it, send an email to signalk+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/signalk/edade509-a082-4af2-990e-d2fde0796c45n%40googlegroups.com.

Владимир Калачихин

unread,
May 2, 2022, 4:29:28 PM5/2/22
to Signal K
понедельник, 2 мая 2022 г. в 17:19:05 UTC+3, Teppo Kurki:
Why would the file not be there and what should happen if it is not, as there is nothing on the client side you can do about it?

In the client side - nothing, of course. But in the server plugin I could download the file from the internet and return it.
Yes, that's how the cache-proxy works.

 
If you need to do anything more complex I suggest you use registerWithRouter, I just added documentation for it at https://github.com/SignalK/signalk-server/blob/master/SERVERPLUGINS.md#exposing-custom-http-paths. Then you can do more complex stuff.

Am I right in thinking that it should be something like this?:
```
function registerWithRouter(router){
    router.use(function (req, res, next) {
        //
        next()
    });
    router.get('/*', function (req, res, next) {
        //
    })
};
```
 
This is better than using Express directly, as your plugin stuff gets mounted under a plugin specific prefix. 

 And `router.use` is not embedded in all routes at all, like `app.use`, right?

Teppo Kurki

unread,
May 3, 2022, 1:34:25 AM5/3/22
to sig...@googlegroups.com
Yes x 2. 


--
You received this message because you are subscribed to the Google Groups "Signal K" group.
To unsubscribe from this group and stop receiving emails from it, send an email to signalk+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages