开发者社区> 问答> 正文

关于函数计算在浏览器端使用的问题

以下代码:

const FCClient = require('@alicloud/fc');
const serviceName = 'tst';
const funcName = 'gettoken';


const client = new FCClient('???', {
  accessKeyID: '???',
  accessKeySecret: '???',
  region: 'cn-shanghai',
  timeout: 10000 // Request timeout in milliseconds, default is 10s
});


client.invokeFunction(serviceName, funcName, 'event').then(function(resp) {
  console.log('invokeFunction: %j', resp);
  console.log(`${JSON.stringify(resp)}`);
}).catch(function(err) {
  console.error(err);
});


经本人测试,可以在node环境中执行,但我需要在浏览器端执行;
既然函数计算是serverless架构,肯定希望能在浏览器中直接调用。


结果返回如下错误:

1226487980969891.fc.cn-shanghai.aliyuncs.com/2016-08-15/services/tst/functions/gettoken/invocations Failed to load resource: the server responded with a status of 400 (Bad Request)
09:39:40.947 1226487980969891.fc.cn-shanghai.aliyuncs.com/2016-08-15/services/tst/functions/gettoken/invocations Failed to load resource: the server responded with a status of 400 (Bad Request)
09:39:40.947 localhost/:1 Failed to load 1226487980969891.fc.cn-shanghai.aliyuncs.com/2016-08-15/services/tst/functions/gettoken/invocations: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 400. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
09:39:40.948 proxyConsole.js:54 TypeError: Failed to fetch POST 1226487980969891.fc.cn-shanghai.aliyuncs.com/2016-08-15/services/tst/functions/gettoken/invocations failed.

展开
收起
downup2u 2017-09-28 09:44:40 2152 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
WEB浏览器中即将发生的安全变化 立即下载
基于浏览器的实时构建探索之路 立即下载
基于浏览器的实时构建探索之路--玄寂 立即下载