framework icon indicating copy to clipboard operation
framework copied to clipboard

How to set CORS for public files?

Open aalfiann opened this issue 2 years ago • 3 comments

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

aalfiann avatar Jan 16 '23 22:01 aalfiann

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

exports.install = function() {
    CORS();
    // your routes
};

petersirka avatar Jan 16 '23 22:01 petersirka

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

is it because I've had many controller files?

aalfiann avatar Jan 18 '23 10:01 aalfiann

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

  • https://corstest.totaljs.com/test.html
  • https://corstest.totaljs.com/test.txt
  • https://corstest.totaljs.com/test.js

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

petersirka avatar Jan 22 '23 18:01 petersirka