试图找出是否可以使用本机代码(使用 N-API)运行 firebase 云功能。我有一个简单的“hello world”示例,它在模拟器下运行良好,但是当我尝试部署它时,我收到 INVALID_ARGUMENT 错误:
status: {
code: 3
message: "INVALID_ARGUMENT"
}
这不是很丰富......只是想知道是否有人可以阐明这种情况。谢谢!
这是功能:
'use strict';
const functions = require('firebase-functions');
exports.helloWorld = functions.https.onRequest(async(request, response) => {
console.time('Program runtime');
const testAddon = require('bindings')('testaddon.node')
const {promisify} = require('util');
module.exports = testAddon;
const asyncCommand = testAddon.hello();
try {
const result = await asyncCommand;
console.log('CONTENT:', result);
response.send(result);
}
catch (err) {
console.log('ERROR:', err);
response.send('ERROR:', err);
}
console.timeEnd('Program runtime');
});
和相应的 C++ 源代码:
#include <napi.h>
namespace functionexample {
std::string hello();
Napi::String HelloWrapped(const Napi::CallbackInfo& info);
Napi::Object Init(Napi::Env env, Napi::Object exports);
}
#include "functionexample.h"
std::string functionexample::hello(){
return "Hello World";
}
Napi::String functionexample::HelloWrapped(const Napi::CallbackInfo& info)
{
Napi::Env env = info.Env();
Napi::String returnValue = Napi::String::New(env, functionexample::hello());
return returnValue;
}
Napi::Object functionexample::Init(Napi::Env env, Napi::Object exports)
{
exports.Set(
"hello", Napi::Function::New(env, functionexample::HelloWrapped)
);
return exports;
}