eclipse-thingweb / node-wot

Components for building WoT devices or for interacting with them over various IoT protocols
https://thingweb.io
Other
161 stars 78 forks source link

[discussion] Hosting Static Files #1018

Open egekorkan opened 1 year ago

egekorkan commented 1 year ago

In the links section of the exposed TD, we can manually write the URLs of documents hosted somewhere. However, node-wot is not capable of hosting these on its own. This means that we need to separately host and manage some documents that are actually closely linked to the Thing. The examples I have:

These are not property affordances semantically so putting them under properties is not a question (for me).

The reason I have put the discussion prefix is to see if there are actually more who think that this would be helpful. @FadySalama had triggered the discussion so there are at least 2 people interested.

Note 1: In the case of linked TMs, we would even need to host all the linked TMs that are linked in the TM linked in the TD. Thus, it might make more sense to do this in a generic fashion and mandate that all such static resources should be put under a specific directory and node-wot just serves them.

Note 2: The protocol to use is probably important. HTTP makes sense here since an HTML/Web interface should be served over HTTP. The biggest question is what happens when we only have a CoAP or MQTT binding in the servient. Should we not host those static files at all or push an HTTP binding into the servient? I think the first one makes more sense and a warning can be displayed when the HTTP binding is not included.

danielpeintner commented 1 year ago

I am a bit unsure whether hosting static files should be done in node-wot. I see your valid points, on the other hand I wonder whether a dedicated server would be better suited.

As you described, HTTP might be a good choice, but what if in node-wot CoAP only is required, shall we still include HTTP. Hence, if we leave hosting of static files outside node-wot, any application can choose the means that serves best...

Having said that, writing a simple webserver in Node.js is not difficult. The only downside I see is that one needs to pick two different ports (one for node-wot and one for the webserver).

egekorkan commented 1 year ago

The only downside I see is that one needs to pick two different ports (one for node-wot and one for the webserver).

The other downside would be writing the partial TD that goes into the produce method. If we have a folder with all the static files, they would be all picked up, links auto-generated, static address and port managed in the same place. In the case of TMs (like in note 1), even a simple web server would need some custom code.

relu91 commented 1 year ago

These are not property affordances semantically so putting them under properties is not a question (for me).

100% agree. One option to achieve this feature is to blend (or make it work) node-wot with fastify/express/etc. which is something I looked into and it is not that hard. However, this means that support for static files is HTTP only and requires working with external libraries. It could be start...