ThingWorx Flow > ThingWorx Flow のインストールと管理 > ThingWorx Flow の管理 > ThingWorx Flow に対する外部呼び出し
ThingWorx Flow に対する外部呼び出し
ThingWorx Flow に対して外部呼び出しを行うには、次のいずれかの方法に従います。
外部 Web サイトから ThingWorx Flow に対する REST 呼び出し
Web サイトが ThingWorx Flow サーバーに対して REST 呼び出しを行おうとした場合、これは異なるオリジンのリクエストなのでサーバーにブロックされます。これを可能にするには、Web サイトからの異なるオリジンのリクエストを許可するように、ThingWorx Flow サーバーを設定する必要があります。CORS (Cross-Origin Resource Sharing) フィルタを ThingWorx Flow サーバーに追加し、異なるオリジンのリクエストを有効にします。別のサーバーに展開されたその他の Web サイトが、ThingWorx Flow サーバーのデータにアクセスできるようになります。
Web サイトから ThingWorx Flow に対して REST 呼び出しを行えるようにするには、次の手順を完了します。
1. 実行中の Nginx インスタンスがあればシャットダウンします。
2. Nginx インストールディレクトリの次の場所にある vhost-flow.conf ファイルを開きます。
Windows: C:/Program Files/nginx-<バージョン>/conf/conf.d
Linux: /etc/nginx/conf/conf.d
3. vhost-flow.conf ファイルの location /Thingworx セクションで、proxy_set_header X-Content-Type-Options nosniff; 行を見つけて、次の行を追加します。
set $cors '';
# Right side of condition can be regular expression:
# if ($http_origin ~ '^https?://(localhost|www\.yourdomain\.com|www\.yourotherdomain\.com)')
if ($http_origin = '<ThingWorx Flow の呼び出し元>') {
set $cors 'true';
}
if ($cors = 'true') {
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
}
# OPTIONS indicates a CORS pre-flight request
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '$http_origin';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
4. ThingWorx FoundationThingWorx Flow を異なるマシンにインストールしている場合、以下の操作を行います。
vhost-flow.conf ファイルで以下の行を見つけます。
# add_header Content-Security-Policy
上記の行の下に以下の行を追加します。
add_header Content-Security-Policy "frame-ancestors 'self' <ThingWorx Flow の呼び出し元>;";
ドメイン名をハードコード化するか、正規表現を入力できます。例: add_header Content-Security-Policy "frame-ancestors 'self' https://*.ptcnet.ptc.com;";
5. <ThingWorx Flow の呼び出し元> を、ThingWorx Flow にアクセスしようとする Web サイトの URL で置き換えます。
6. Nginx サービスを再起動します。
ThingWorx Flow に対する WebSocket 呼び出し
デフォルトでは、ThingWorx Flow に対して WebSocket Secure (wss) 呼び出しを行えます。
WebSocket (ws) 呼び出しはサポートされていません。