【问题标题】:How to set up CORS with Drupal 8如何使用 Drupal 8 设置 CORS
【发布时间】:2017-03-31 20:40:31
【问题描述】:

我正在设置一个带有视图的视图,显示为rest JSON,我如何为它设置Cross-Origin Resource Sharing (CORS)

我想解决方案是修改https://www.drupal.org/node/2715637 指示的default.services.yml,我已经这样做了。

但我仍然无法从其他主机请求 JSON 资源。有人知道如何解决这个问题吗?

谢谢

【问题讨论】:

  • 问题是......一旦你更新了yml文件,你是否重启了apache服务?

标签: drupal cors drupal-8


【解决方案1】:

我为此写了一篇博客,checkit

查找:.../sites/default/default.services.yml

制作一个副本并将副本重命名为:

.../sites/default/services.yml

找到这部分代码:cors.config: enabled: false

并替换为以下内容 - cors.config: enabled: true

添加您要分享的网站,例如:

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: ['http://localhost:4200']
    # 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

清除缓存。

【讨论】:

    猜你喜欢
    • 2017-12-25
    • 2019-02-26
    • 1970-01-01
    • 2019-02-02
    • 2020-03-20
    • 2016-04-04
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多