以下代码:
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.
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。