totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

How to set CORS for public files? #796

Open aalfiann opened 1 year ago

aalfiann commented 1 year ago

To access public files, I didn't use controller to handle this

It's just direct access to the url path and its working.

but the problem is, when I use ajax to get the files, it's blocked by Cross Origin.

How to solve this?

Btw, I use TotalJS 3. Thank you

petersirka commented 1 year ago

Hi @aalfiann, just add CORS() method to a controller e.g.

exports.install = function() {
    CORS();
    // your routes
};
aalfiann commented 1 year ago

I've tried, but still doesn't work..

is it because I've had many controller files?

petersirka commented 1 year ago

@aalfiann sorry for the delay. I have prepared a test. You can test the links below:

I have tested them from another domain and everything works correctly.