我遇到了问题,我的节点 js 服务器出现在 cloudflare 主机上,问题是我的问题。我已将 Cloudflare 发布到 github 版本,并且 Cloudflare 已在我的 github 存储库中发布。 Ganz wichtig ist,dass auf Cloudflare die Datei index.mjs gestartet wird。 Wenn ich jetzt aber npm run index.mjs oder node index.mjs bei Start 命令 eingebe,kommt nur eine Fehlermeldung。
我可以在该网站上登录并访问仪表板。 Ganz wichtig ist auch noch das EJS dann noch funktioniert。 Hier noch ein der link zum github 存储库:https://github.com/Julcedev/bes-wirtschaft
要在 Cloudflare Workers 上部署 Node.js 应用程序,请按照以下步骤操作:
npm install -g cf
cd path/to/your/project
cf init
这将在项目根目录中创建一个
cf
文件夹,其中包含必要的配置文件。
2. 使用您的 Cloudflare API 密钥更新 cf/settings.json
文件。将占位符值替换为您的实际 API 密钥:
{
"account_id": "your_cloudflare_account_id",
"api_email": "your_cloudflare_api_email",
"api_key": "your_cloudflare_api_key"
}
npm install --save cloudflare-workers
index.mjs
文件以导出 Cloudflare Workers 所需的主要功能:// index.mjs
const handler = async (event) => {
// Your existing code here
};
export default handler;
cf build
这将编译您的代码并将其部署到 Cloudflare 边缘网络。 2. 部署成功后,您可以使用
cf wrangler
命令行工具来管理您的工作线程和域设置。您可以设置您的域的默认路由指向工作人员:
cf wrangler routeset --primary index.mjs your-cloudflare-domain
将
index.mjs
替换为您的主工作文件的文件名,将 your-cloudflare-domain
替换为您的实际域名。
现在,您的 Node.js 应用程序应该在 Cloudflare Workers 上运行。请务必检查日志中是否有任何错误消息并相应地调整您的代码。