Skip to content

Commit

Permalink
Enable collection endpoint using Backbone.Drupal configuration, updat…
Browse files Browse the repository at this point in the history
…ed documentation
  • Loading branch information
enzolutions committed Jan 3, 2015
1 parent ca83e78 commit d27898f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
48 changes: 21 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,40 +131,34 @@ Check the releases section to verify the latest version.

##Cross-origin

Enable to have Drupal as Backend in a Domain backend.com and the Backbone/Marionette App in other domain frontend.com.
Using [CORS](http://enzolutions.com/articles/2014/05/31/what-is-cross-origin-resource-sharing-cors/) we can use Drupal as Backend Server in a Domain i.e **backend.com** and user a Backbone/Marionette App as Front End server in other domain i.e **frontend.com**.

### Drupal 8

Because the mode https://www.drupal.org/project/cors doesn't have a version for Drupal 8 yet and Drupal Core still doesn't have a solution for that I did a <a href="https://www.drupal.org/files/issues/core-cors-headers-1869548-26.patch">patch</a> for .htacces to enable CORS request using jQuery documented in issue # https://www.drupal.org/node/1869548#comment-9120317
Because the Drupal module [CORS](https://www.drupal.org/project/cors) doesn't have a version for Drupal 8 yet and Drupal Core won't have a native solution for that until Drupal 8.1.

I propose a <a href="https://www.drupal.org/files/issues/core-cors-headers-1869548-26.patch">patch</a> for .htacces in order to enable CORS requests using jQuery documented in [issue](https://www.drupal.org/node/1869548#comment-9120317)

In summary you only have to accept the OPTIONS requests as you can see in the following instructions to .htacces
```
diff --git a/.htaccess b/.htaccess
index c32b182..b0bf563 100644
--- a/.htaccess
+++ b/.htaccess
@@ -118,6 +118,10 @@ DirectoryIndex index.php index.html index.htm
RewriteCond %{REQUEST_URI} !core
RewriteRule ^ %1/core/%2 [L,QSA,R=301]
+ # Intercept OPTIONS calls
+ RewriteCond %{REQUEST_METHOD} OPTIONS
+ RewriteRule .* / [R=200,L]
+
# Pass all requests not referring directly to files in the filesystem to
# index.php.
RewriteCond %{REQUEST_FILENAME} !-f
@@ -165,3 +169,7 @@ DirectoryIndex index.php index.html index.htm
</FilesMatch>
</IfModule>
</IfModule>
+
+Header always set Access-Control-Allow-Origin "*"
+Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, PATCH, DELETE"
+Header always set Access-Control-Allow-Headers: Authorization
# Intercept OPTIONS calls
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule .* / [R=200,L]
```

Also we have to enable REST Methdos POST, GET, OPTIONS, PATCH, DELETE and allow request from different origin. Check the instructions below.

```
<IfModule mod_headers.c>
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, PATCH, DELETE"
Header always set Access-Control-Allow-Headers: Authorization
</IfModule>
```
When issues https://www.drupal.org/node/1869548 and https://www.drupal.org/node/2237231 get resolved this implementation will be updated.

More information at http://enable-cors.org/server_apache.html
Also a intructions to enable Basic Auth is required.

When issues https://www.drupal.org/node/1869548 and https://www.drupal.org/node/2237231 get resolved this implementation will be updated.

#### Auth

Expand Down
6 changes: 5 additions & 1 deletion backbone.drupal.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ Backbone.Drupal.Collections.Base = Backbone.Collection.extend({
}
// Call Super fetch function with options array including any collection params.
Backbone.Collection.prototype.fetch.call(this, options);
}
},
url: function() {
var url_endpoint = Backbone.Drupal.restEndpoint.root + '/' + this.urlSource;
return url_endpoint;
},
});

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"backbone.drupal.js",
"backbone.drupal.services.js"
],
"version": "0.2.0-beta",
"version": "0.2.1-alpha",
"homepage": "http://enzolutions.com/projects/backbone_drupal/",
"author": {
"name": "enzo - Eduardo Garcia",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "backbone.drupal",
"description": "Allows backbone models to work with Drupal via REST.",
"version": "0.2.0-beta",
"version": "0.2.1-alpha",
"homepage": "https://github.com/enzolutions/backbone.drupal",
"author": {
"name": "enzo - Eduardo Garcia",
Expand Down

0 comments on commit d27898f

Please sign in to comment.