我尝试在 deno supabase 边缘函数中使用/导入用于 Node-js 的 web-push 库(https://github.com/web-push-libs/web-push),但它不起作用。
我的代码
import * as webPush from "https://dev.jspm.io/web-push"
Deno.serve(async (req) => {
const vapidKeys = {
publicKey: '<The public Key',
privateKey: '<The private Key>',
}
const webpush = webPush;
webpush.setGCMAPIKey('<The GCM API Key>'); // TODO: I think this line times out
webpush.setVapidDetails(
'mailto:[email protected]',
vapidKeys.publicKey,
vapidKeys.privateKey
);
看起来加密库存在兼容性问题。我在 Deno 和 Node 中构建了相同的应用程序,并且在处理私钥时出现错误,Deno 崩溃了:
error: Uncaught TypeError: Invalid PEM label
at SignImpl.sign (ext:deno_node/internal/crypto/sig.ts:36:33)
at sign (file:///Users/aekidna/Library/Caches/deno/npm/registry.npmjs.org/jwa/2.0.0/index.js:152:45)
at Object.sign (file:///Users/aekidna/Library/Caches/deno/npm/registry.npmjs.org/jwa/2.0.0/index.js:200:27)
at Object.jwsSign [as sign] (file:///Users/aekidna/Library/Caches/deno/npm/registry.npmjs.org/jws/4.0.0/lib/sign-stream.js:32:24)
at Object.getVapidHeaders (file:///Users/aekidna/Library/Caches/deno/npm/registry.npmjs.org/deno-web-push/3.5.0/src/vapid-helper.js:217:19)
at Object.WebPushLib.generateRequestDetails (file:///Users/aekidna/Library/Caches/deno/npm/registry.npmjs.org/deno-web-push/3.5.0/src/web-push-lib.js:253:40)
at Object.WebPushLib.sendNotification (file:///Users/aekidna/Library/Caches/deno/npm/registry.npmjs.org/deno-web-push/3.5.0/src/web-push-lib.js:310:29)
我尝试使用 esm 和
target=deno
导入 web-push,但这会导致另一个与 crypto.ECDH
的实现相关的错误(未实现)
我很惊讶没有人关注这个。