I am trying to create a new node using drupal 8's restful API through Angular and I cannot seem to figure it out. My angular app has a domain of http://ang.dev:8888
and my drupal install has a domain of http://dang.dev:8888
When I make my request my D8 install returns 2 lines to the console:
OPTIONS http://dang.dev:8888/entity/node
XMLHttpRequest cannot load http://dang.dev:8888/entity/node. Response for preflight has invalid HTTP status code 415
My drupal 8 install is located at http://dang.dev:8888 and according to this page, /entity/node
is where you can POST to create a new node.
My service for submitting the new article is below:
app.service('D8', function($http, Token) {
var config = {
headers: {
'Content-Type': 'application/hal+json',
'Authorization': 'Basic YWRtaW46YWRtaW4=',
'X-CSRF-Token': ''
},
timeout: 20000
};
var token = Token.setToken().then(function(response) {
config.headers['X-CSRF-Token'] = response.data;
log(config.headers);
});
return {
submitArticle: function(title, body) {
var params = {
type: [{'target_id': 'article'}],
title: [{'value': title}],
body: [{'value': body}]
};
return $http.post('http://dang.dev:8888/entity/node?_format=hal_json', params, config);
}
}
});
the X-CSRF-Token
is already set by the time I make the request to submit an article.
EDIT
Enabled CORS via .htaccess
on dang.dev so ang.dev can hit it:
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