我正在使用rasa chatbot,并且正在尝试调用操作端点api。但是我遇到了错误:
跨域请求被阻止:“同源起源”策略禁止读取http://192.168.2.9:5055/webhooks/rest/webhook处的远程资源。 (原因:CORS标头“ Access-Control-Allow-Origin”缺失)
当我尝试访问action_endpoint时,出现上述错误。我正在使用rasa 1.0.6
这是我以前运行的命令 rasa run --cors [“ *”] --endpoints endpoints.yml --debug --enable-api 并采取以下行动: python3 -m rasa_core_sdk.endpoint --actions操作
在浏览器控制台中,出现错误:
跨域请求被阻止:“同源起源”策略禁止读取http://192.168.2.9:5055/webhooks/rest/webhook处的远程资源。 (原因:CORS标头“ Access-Control-Allow-Origin”缺失)。
在操作结束时,
192.168.2.56--[2019-09-17 09:58:44]“选项/ webhooks / rest / webhook HTTP / 1.1” 404 341 2.407519
我使用nginx服务器托管了静态网页。
这是nginx的配置
/ etc / nginx / sites-available / default 服务器{ 监听80 default_server; 听[::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/rasachat/Chat-2;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#add_header 'Access-Control-Allow-Origin' 'origin-list'
add_header 'Access-Control-Allow-Origin' '*';
try_files $uri $uri/ =404;
}
}
endpoints.yml
action_endpoint:
url: http://192.168.2.9:5055/webhook
credential.yml
rest:
rasa:
url: "http://192.168.2.9:5002/api"
*。js
$.ajax({
url: "http://192.168.2.9:5055/webhooks/rest/webhook",
contentType: 'application/json; charset=utf-8',
type:"POST",
data:
JSON.stringify({"sender":"Rasa",
"message":userMsg
}),
success: function(results){
generateMessage(results,'user',INDEXX);
}
});
我该如何解决?