node js 服务器托管

问题描述 投票:0回答:1

我遇到了问题,我的节点 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

node.js cloudflare
1个回答
0
投票

要在 Cloudflare Workers 上部署 Node.js 应用程序,请按照以下步骤操作:

  1. 确保您已安装 Cloudflare CLI。如果没有,请使用以下命令安装:
npm install -g cf
  1. 导航到您的项目目录:
cd path/to/your/project
  1. 初始化一个新的 Cloudflare Worker 项目:
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"
}
  1. 安装 Cloudflare Workers 所需的依赖项:
npm install --save cloudflare-workers
  1. 更新您的
    index.mjs
    文件以导出 Cloudflare Workers 所需的主要功能:
// index.mjs
const handler = async (event) => {
  // Your existing code here
};

export default handler;
  1. 构建并部署您的 Cloudflare Worker:
cf build

这将编译您的代码并将其部署到 Cloudflare 边缘网络。 2. 部署成功后,您可以使用

cf wrangler
命令行工具来管理您的工作线程和域设置。您可以设置您的域的默认路由指向工作人员:

cf wrangler routeset --primary index.mjs your-cloudflare-domain

index.mjs
替换为您的主工作文件的文件名,将
your-cloudflare-domain
替换为您的实际域名。

现在,您的 Node.js 应用程序应该在 Cloudflare Workers 上运行。请务必检查日志中是否有任何错误消息并相应地调整您的代码。

© www.soinside.com 2019 - 2024. All rights reserved.