From d27898f19b31c1b3949fee2f14093bef7566846d Mon Sep 17 00:00:00 2001 From: enzo - Eduardo Garcia Date: Sat, 3 Jan 2015 17:10:36 -0600 Subject: [PATCH] Enable collection endpoint using Backbone.Drupal configuration, updated documentation --- README.md | 48 ++++++++++++++++++++-------------------------- backbone.drupal.js | 6 +++++- bower.json | 2 +- package.json | 2 +- 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 9930b07..b257d52 100644 --- a/README.md +++ b/README.md @@ -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 patch 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 patch 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 - - - -+ -+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. + +``` + + 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 + ``` -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 diff --git a/backbone.drupal.js b/backbone.drupal.js index a98e92a..cff9849 100644 --- a/backbone.drupal.js +++ b/backbone.drupal.js @@ -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; + }, }); diff --git a/bower.json b/bower.json index 6b5d14c..51f527e 100644 --- a/bower.json +++ b/bower.json @@ -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", diff --git a/package.json b/package.json index e6eb4c2..c6cd131 100644 --- a/package.json +++ b/package.json @@ -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",