Skip to content

Commit d27898f

Browse files
committed
Enable collection endpoint using Backbone.Drupal configuration, updated documentation
1 parent ca83e78 commit d27898f

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

README.md

+21-27
Original file line numberDiff line numberDiff line change
@@ -131,40 +131,34 @@ Check the releases section to verify the latest version.
131131

132132
##Cross-origin
133133

134-
Enable to have Drupal as Backend in a Domain backend.com and the Backbone/Marionette App in other domain frontend.com.
134+
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**.
135135

136136
### Drupal 8
137137

138-
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
138+
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.
139139

140+
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)
141+
142+
In summary you only have to accept the OPTIONS requests as you can see in the following instructions to .htacces
140143
```
141-
diff --git a/.htaccess b/.htaccess
142-
index c32b182..b0bf563 100644
143-
--- a/.htaccess
144-
+++ b/.htaccess
145-
@@ -118,6 +118,10 @@ DirectoryIndex index.php index.html index.htm
146-
RewriteCond %{REQUEST_URI} !core
147-
RewriteRule ^ %1/core/%2 [L,QSA,R=301]
148-
149-
+ # Intercept OPTIONS calls
150-
+ RewriteCond %{REQUEST_METHOD} OPTIONS
151-
+ RewriteRule .* / [R=200,L]
152-
+
153-
# Pass all requests not referring directly to files in the filesystem to
154-
# index.php.
155-
RewriteCond %{REQUEST_FILENAME} !-f
156-
@@ -165,3 +169,7 @@ DirectoryIndex index.php index.html index.htm
157-
</FilesMatch>
158-
</IfModule>
159-
</IfModule>
160-
+
161-
+Header always set Access-Control-Allow-Origin "*"
162-
+Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, PATCH, DELETE"
163-
+Header always set Access-Control-Allow-Headers: Authorization
144+
# Intercept OPTIONS calls
145+
RewriteCond %{REQUEST_METHOD} OPTIONS
146+
RewriteRule .* / [R=200,L]
147+
```
148+
149+
Also we have to enable REST Methdos POST, GET, OPTIONS, PATCH, DELETE and allow request from different origin. Check the instructions below.
150+
151+
```
152+
<IfModule mod_headers.c>
153+
Header always set Access-Control-Allow-Origin "*"
154+
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, PATCH, DELETE"
155+
Header always set Access-Control-Allow-Headers: Authorization
156+
</IfModule>
164157
```
165-
When issues https://www.drupal.org/node/1869548 and https://www.drupal.org/node/2237231 get resolved this implementation will be updated.
166158

167-
More information at http://enable-cors.org/server_apache.html
159+
Also a intructions to enable Basic Auth is required.
160+
161+
When issues https://www.drupal.org/node/1869548 and https://www.drupal.org/node/2237231 get resolved this implementation will be updated.
168162

169163
#### Auth
170164

backbone.drupal.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ Backbone.Drupal.Collections.Base = Backbone.Collection.extend({
319319
}
320320
// Call Super fetch function with options array including any collection params.
321321
Backbone.Collection.prototype.fetch.call(this, options);
322-
}
322+
},
323+
url: function() {
324+
var url_endpoint = Backbone.Drupal.restEndpoint.root + '/' + this.urlSource;
325+
return url_endpoint;
326+
},
323327
});
324328

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"backbone.drupal.js",
55
"backbone.drupal.services.js"
66
],
7-
"version": "0.2.0-beta",
7+
"version": "0.2.1-alpha",
88
"homepage": "http://enzolutions.com/projects/backbone_drupal/",
99
"author": {
1010
"name": "enzo - Eduardo Garcia",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "backbone.drupal",
33
"description": "Allows backbone models to work with Drupal via REST.",
4-
"version": "0.2.0-beta",
4+
"version": "0.2.1-alpha",
55
"homepage": "https://github.com/enzolutions/backbone.drupal",
66
"author": {
77
"name": "enzo - Eduardo Garcia",

0 commit comments

Comments
 (0)