Giter VIP home page Giter VIP logo

Comments (4)

Jehu avatar Jehu commented on August 15, 2024

Found out, if i add the following to my .htaccess file, the same domain origin problem is solved:

<ifModule mod_headers.c>
    Header set Access-Control-Allow-Origin: "*"
    Header set Access-Control-Allow-Headers "X-Requested-With"
</ifModule>

"Access-Control-Allow-Headers" is needed too! Now i get some Data due GET request

But there is still a problem:
There are two requests:

  1. OPTIONS-Request: fails (same as in my initial issue-post)
  2. GET-Request: success (works now due .htaccess changes)

So i've added the followin Rewrite Rule:

RewriteEngine On                  
RewriteCond %{REQUEST_METHOD} OPTIONS 
RewriteRule ^(.*)$ $1 [R=200,L] 

And changed the header settings like so:

<ifModule mod_headers.c>
    Header always set Access-Control-Allow-Origin: "*"
    Header always set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
    Header always set Access-Control-Allow-Headers "X-Requested-With"
</ifModule>

Now it works perfectly, so far...
What if i could'nt work with .htaccess?

from restangular.

mgonto avatar mgonto commented on August 15, 2024

Hey,

Per my understanding, this is a configuration that is needed for any app that has Cross Site HTTP Request. If you didn't have .htaccess, you'd have another file to configure this properties, as all servers do.

The thing here is that you have 2 Stand alone apps which represents "different sites".

The header "X-Requested-With" isn't added by Restangular, it's being added by $http.

Restangular doesn't do any request by itself. Restangular delegates requests to $resource and to $http which are native to AngularJS, so you'd have this same problem if using them without Restangular, so there's nothing else I can do about this unfourtenately. But as I said, you'll always have the opportunity to configure this somewhere.

I hope this answer helps you!

Bests,
Gonto

from restangular.

Jehu avatar Jehu commented on August 15, 2024

Hey Gonto,

thank your for the response.
You are right. My question was not so resangular-specific as i thought first.
Full REST is not provided due JSONP (JSONP only has the GET method). So it does make no sense to handle it by restangular. For me it is now clear how to deal with this cross domain thing for a full RESTful API on serverside.

Thanks for your work on resangular!

Regards
Jehu

from restangular.

mgonto avatar mgonto commented on August 15, 2024

Thank you for using it and giving feedback!

Closing it then!

from restangular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.