数字海洋空间类型错误[ERR_INVALID_URL]:无效的URL



我正在本地的express中创建一个Shopify应用程序,并收到此错误。当我在服务器上使用此应用程序时,同样的代码也在工作。我不知道为什么这在当地环境中不起作用。

我使用的是Digital Ocean Spaces,Node.js v17.0.1,@aws sdk/client-s3 v3.171.0。

import { S3 } from "@aws-sdk/client-s3";
import dotenv from "dotenv";
dotenv.config();
const s3Client = new S3({
endpoint: process.env.SPACES_ENDPOINT,
region: process.env.SPACES_REGION,
credentials: {
accessKeyId: process.env.SPACES_KEY,
secretAccessKey: process.env.SPACES_SECRET,
},
});
export default s3Client;

我已经在.env文件中放置了有效的env变量。

这是错误

burhan@burhan:/shopifynode$ shopify app serve
✓ ngrok tunnel running at https://ebb6-2401-4900-1c02-5a90-982c-9e83-1b5e-b9ee.ngrok.io, with account testmail@mail.com
✓ .env saved to project root
⭑ To install and start using your app, open this URL in your browser:
https://ebb6-2401-4900-1c02-5a90-982c-9e83-1b5e-b9ee.ngrok.io/login?shop=my-app-staging.myshopify.com
Running server…
> dev
> cross-env NODE_ENV=development nodemon server/index.js --watch ./server
[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): server/**/*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server/index.js`
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:371:5)
at onParseError (node:internal/url:552:9)
at new URL (node:internal/url:632:5)
at parseUrl (/shopifynode/node_modules/@aws-sdk/url-parser/dist-cjs/index.js:7:38)
at resolveEndpointsConfig (/shopifynode/node_modules/@aws-sdk/config-resolver/dist-cjs/endpointsConfig/resolveEndpointsConfig.js:14:87)
at new S3Client (/shopifynode/node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js:22:72)
at new S3 (/shopifynode/node_modules/@aws-sdk/client-s3/dist-cjs/S3.js:98:1)
at file:///shopifynode/server/helpers/s3-client.js:6:18
at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
at async Promise.all (index 0) {
input: '"https://fra1.digitaloceanspaces.com"',
code: 'ERR_INVALID_URL'
}
Node.js v17.0.1
[nodemon] app crashed - waiting for file changes before starting...

这里只是猜测,但我在从aws-sdk2迁移到aws-sdk3时遇到了同样的问题:似乎v2允许终结点不包含协议。在v3中,它肯定需要它。检查你的env-var,也许可以在它前面加上"https://"。

相关内容

  • 没有找到相关文章

最新更新