0

Im working with Drupal 8 and Angular.

I want to create a content from angular.

I have the Get method working.

The problem is with the Post method, I don't know how to configure it.

With the Rest Ui module, i have this configuration:

enter image description here

And in the services.yml file I have this one:

  cors.config:
    enabled: true
    # Specify allowed headers, like 'x-allowed-header'.
    allowedHeaders: []
    # Specify allowed request methods, specify ['*'] to allow all possible ones.
    allowedMethods: []
    # Configure requests allowed from specific origins.
    allowedOrigins: ['*']
    # Sets the Access-Control-Expose-Headers header.
    exposedHeaders: false
    # Sets the Access-Control-Max-Age header.
    maxAge: false
    # Sets the Access-Control-Allow-Credentials header.
    supportsCredentials: false

It works fine for the Get method, but for the POST, it gives me this error:

XMLHttpRequest cannot load http://drupal.dd:8083/entity/node. Preflight response is not successful task.service.ts:92

The task.service.ts is from my Angular app.

Questions:

1) Is the problem from Drupal configuration or from angular? (if is from angular, i will move the post. )

2)Wich on is the correct way to configure Post Method in Drupal?

Extra info from the method enter image description here

1
  • allowedMethods: [] means no methods are allowed. So the OPTIONS call fails. Add the appropriate methods to that array, clear the cache, it should work
    – Clive
    Dec 15, 2017 at 12:03

1 Answer 1

1

This is the right cors.config configuration:

 cors.config:
        enabled: true
        # Specify allowed headers, like 'x-allowed-header'.
        allowedHeaders: ['*']
        # Specify allowed request methods, specify ['*'] to allow all possible ones.
        allowedMethods: ['*']
        # Configure requests allowed from specific origins.
        allowedOrigins: ['*']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.