marcoschwartz / node-aREST

Node.js module for the aREST framework
http://aREST.io/
11 stars 10 forks source link

GET Route Disallows Loading of External Resources #5

Open Tresky opened 8 years ago

Tresky commented 8 years ago

Hello!

I have encountered an issue where the following routes disallows the loading of external css/js/etc.

$.get('/:device/:command', function(req, res) { ... });

This library will detect the get commands issued by standard <script> and <link> tags and think that I am sending data over the aREST system. This will mean that my CSS and JS don't get loaded. The way that I fixed this was to change the GET command to be the following:

$.get('/send/:device/:command', function(req, res) { ... });

Thanks, Tresky

marcoschwartz commented 8 years ago

Hello! What do you means exactly by external CSS? For example CSS files on another server ?

Tresky commented 8 years ago

Hello! Thank you for your reply. By external CSS, I am referring to the local CSS files that I am loading via HTML into the project (also the local JS files). Really, this problem comes up because whenever you import a local file (such as CSS and JS) the browser issues a GET request to localhost to retrieve the files.

I found that this interferes with the predefined /:device/:command route. The browser issues a GET for my local file called styles.css and the Node mistakes "styles" as a referral to the "device" route. This is possible because ":device" is not consistent and could be anything. So, by concreting the first routes to /send I was able to fix it.

Let me know if you need to attempt to clarify further.

marcoschwartz commented 8 years ago

Got it :) However I never had problems by including CSS files placed in the public/css folder, and importing them via JavaScript. Is that what you are doing as well ?

Tresky commented 8 years ago

I am placing my CSS and JS files in the public folder and including them in my index.html file. I am not using Javascript to import my files.