Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

Posted on
Fri Mar 03, 2023 11:53 pm
jay (support) offline
Site Admin
User avatar
Posts: 18201
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

Yeah, that's not how you serve static content from your plugin. Anything in the Resources folder is available from the following URL:

Code: Select all
https://yourreflector.indigodomo.net/com.yourplugin.id/path/to/file.css


A common file layout would be:
Code: Select all
Resources
    css
        EventLog.css
    js
        prototype.js
        tablekit.js


Then, in your HTML, you would reference them:

Code: Select all
<link rel="stylesheet" type="text/css" href="/com.yourplugin.id/css/EventLog.css">
<script type="text/javascript" src="/com.yourplugin.id/js/prototype.js"></script>
<script type="text/javascript" src="/com.yourplugin.id/js/tablekit.js"></script>


You can also serve static content from your plugin, but you don't really need to do that since everything in the Resources directory is available for free.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Mar 04, 2023 9:20 am
DVDDave offline
Posts: 470
Joined: Feb 26, 2006
Location: San Jose, CA

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

Thanks, Jay. That got me closer and the css file is now served correctly. Although the file was found in any of the locations (given the correct path), the content-type is only made text/css if the file is served from the resources/css directory. I had misunderstood the documentation to say that only public, static, images and videos subdirectories were to be present and I certainly did not understand that the location affects the returned content-type.

That said, the javascript files still aren't working. I don't know if it matters, but the content-type is returned as application/javascript even though it's specified as text/javascript. I'll try to troubleshoot it to see if it is executing at all.

Since the web server seems to use the resource subdirectory at least partially to determine the content-type, is there somewhere in the documentation that explains this relationship?

Thanks for your help and patience with this clueless plugin developer! :?

--Dave

Posted on
Sat Mar 04, 2023 11:40 am
jay (support) offline
Site Admin
User avatar
Posts: 18201
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

DVDDave wrote:
Since the web server seems to use the resource subdirectory at least partially to determine the content-type, is there somewhere in the documentation that explains this relationship?


Not following you...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Mar 04, 2023 12:18 pm
DVDDave offline
Posts: 470
Joined: Feb 26, 2006
Location: San Jose, CA

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

Sorry, I combined too many subjects.

My main question is how is the content-type determined for each of the files? Is it fixed by the server for each type of Resource subdirectory?

eg Why does the content-type of the javascript files end up being application/javascript rather than text/javascript? And why would it be text/html when served from the Resources/static directory?

Posted on
Sat Mar 04, 2023 12:54 pm
jay (support) offline
Site Admin
User avatar
Posts: 18201
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

Our web server library, Sanic, automatically determines what the mime type is when static content is served directly.

BTW, the official mime type for JavaScript is "application/javascript" and according to that RFC "text/javascript" is "obsolete". I think they are both still used commonly.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Mar 04, 2023 12:56 pm
jay (support) offline
Site Admin
User avatar
Posts: 18201
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

DVDDave wrote:
And why would it be text/html when served from the Resources/static directory?


Again, not following you. You have a .js file that's being served automatically from the "Resources" directory with a content-type of "text/html"? That shouldn't happen...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Mar 04, 2023 1:01 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

Try clearing your browser cache, or using a different browser in incognito mode. I think you might have some caching occurring or something, as I don't see how it is possible that it is finding a file with this type of URL:

https://yourreflector.indigodomo.net/com.yourplugin.id/path/to/file.js

in any location except Resources/path/to/file.js.

Image

Posted on
Sat Mar 04, 2023 1:14 pm
DVDDave offline
Posts: 470
Joined: Feb 26, 2006
Location: San Jose, CA

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

I didn't know that Sanic determines the content-type by the directory it's being served from. Sanic had caused the .js file to be returned with a content-type of text/html when the file was in the static or ServerPlugin directory. I could easily see the returned type and whether the file was found in the browser's developer tools. I had cleared the cache many times during each step, including when the js and css directories were mistakenly in the ServerPlugin directory..

Makes sense now. I am no longer trying to serve the files from outside the Resources directory and am careful to put them in the right subdirectory so Sanic applies the right content-type.

Even the Javascript seems to be executing now. I am just having trouble with it that probably has nothing to do with what we've been discussing.

Thanks!

Posted on
Sat Mar 04, 2023 1:18 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

It doesn't determine the type based on the folder name, it determines it based on the file name extension. That logic is used if you are returning a static file using the URL semantics Jay mentioned above (https://yourreflector.indigodomo.net/com.yourplugin.id/path/to/file) . Point being, anything in the Resources folder that is served statically will have its content-type automatically determined based on the file name.

If you are returning data via the message API (https://yourreflector.indigodomo.net/message/com.yourplugin.id/some_action) then the default type is set to JSON. If you wnat something different returned then you have to explicitly set the type you want (I think, not positive).

Image

Posted on
Sat Mar 04, 2023 1:46 pm
jay (support) offline
Site Admin
User avatar
Posts: 18201
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

matt (support) wrote:
you have to explicitly set the type you want (I think, not positive).


Exactly. There is an example in the HTTP Responder SDK plugin of doing your own delivery of static content. You have to set the mime type yourself.

Now, I think I may have found what you were seeing: in that plugin's handle_static_file_request method, we do the following:

Code: Select all
content_type = indigo.utils.FILE_EXTENSION_MIME_MAP.get(os.path.splitext(file_path[-1])[-1].strip("."), "text/plain")


The bug here is that indigo.utils.FILE_EXTENSION_MIME_MAP doesn't contain "js", so it's returning the default of "text/plain" when it finds a ".js" file extension. I'll file a bug on that and we'll get it added in the next release.

But, in the VAST majority of cases, you want to allow the web server to do the serving for you by just including your static assets in the Resources directory. Nothing else you need to do at that point, it all becomes available at the URL I specified in the post above.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Mar 04, 2023 4:16 pm
DVDDave offline
Posts: 470
Joined: Feb 26, 2006
Location: San Jose, CA

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

OK! I think I understand now. The bug you mentioned, plus the fact that files in the Resources/static directory get returned as text/html instead of using the file extension, had me drawing wrong conclusions. Also, initially I mistakenly served the files inside the ServerPlugin directory which returned them all as text/html which confused me even more. Lessons learned! :oops:

Thanks so much for your help and patience!

--Dave

Posted on
Mon Mar 06, 2023 1:40 pm
jay (support) offline
Site Admin
User avatar
Posts: 18201
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

DVDDave wrote:
the fact that files in the Resources/static directory get returned as text/html instead of using the file extension


That's incorrect. When using the automatic static file URL then the web server will return the correct mime type.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Mar 06, 2023 2:09 pm
DVDDave offline
Posts: 470
Joined: Feb 26, 2006
Location: San Jose, CA

Re: Remote Log Viewer (EventLog web plugin) kaput in 2022.2?

Ugh. Thanks for catching this. The other mime type was being returned in an earlier case where I didn't have the URL formed correctly. I checked again and it operates exactly as you said.

I fixed the other issue I was having and all is working well now. Thanks again!

Who is online

Users browsing this forum: No registered users and 4 guests