Sveltekit静态适配器在CloudFlare页面上不起作用

发布于 2025-02-09 20:54:04 字数 208 浏览 3 评论 0 原文

我有一个已部署到CloudFlare页面的Sveltekit网站,问题是,当我使用静态适配器部署该应用程序并尝试访问该网站时,它说“找到网址没有网页”,但是当我使用CloudFlare Adapter时它可以成功地工作,因此我打算使用CloudFlare适配器,但我注意到“今天的功能请求”的数量正在增加,尽管我的应用程序没有任何功能(某些内容如何将每个请求视为服务器函数),那么什么我在这里做错了吗?

I have a sveltekit website that I deployed to cloudflare pages, the problem is that when I deploy the app with the static adapter and try to visit the site it says "No webpage was found for the web address" but when I use the cloudflare adapter it works successfully, so I was intending to use the cloudflare adapter but I noticed that the number of "Functions requests today" was increasing although my app does not have any functions (some how every request is counted as a server function), So what am I doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港小镇 2025-02-16 20:54:04

运行 NPM运行构建构建目录是否包含 index.html 文件?如果不是,您可能需要指定 prerender.default = true so:

import adapter from '@sveltejs/adapter-static';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
        adapter: adapter(),
        prerender: {
            default: true
        }
    }
};

export default config;

使用/build Directory,其中包含 index.html 。接下来只需按照CloudFlare页面文档的说明进行部署 https:// https:// https:/// developers.cloudflare.com/pages/framework-guides/deploy-anything/

这些说明包括以下内容:

'

通过登录 Cloudflare仪表板> 帐户主页> 页面并选择创建一个项目。选择您创建的新的GITHUB存储库,然后在设置中构建和部署部分,提供以下信息:

配置选项
生产分支 MAIN
build>构建命令(可选) <代码>&lt; your_build_command&gt;
构建输出目录 &lt; your_build_dir&gt;

与许多框架指南不同,网站的构建命令和构建目录将完全自定义。如果您不需要构建步骤,请留下构建命令字段空,并指定构建输出目录。构建输出目录是您的应用程序内容所处的位置。

配置网站后,您可以开始第一次部署。您的自定义构建命令(如果提供)将运行,并且页面将部署您的静态站点。

有关将第一个站点部署到CloudFlare页面的完整指南,请参阅

部署网站后,您将在*。页面.dev 上收到一个唯一的子域。 CloudFlare页面将自动重建您的项目并部署该项目。您还将可以在新的拉请请求上访问预览部署,因此您可以在部署将它们部署到生产之前预览网站上的更改外观。

从这些说明中,您似乎只需要将生产分支设置为 main 分支(或者您想要部署的分支)和 构建输出目录构建(除非您的 svelte.config.json 在另外指定)。确保您的.gitignore不包括/build 目录,除非您要使用 build command config config,然后继续进行。

When you run npm run build does the build directory contain an index.html file? If not you may need to specify prerender.default = true like so:

import adapter from '@sveltejs/adapter-static';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
        adapter: adapter(),
        prerender: {
            default: true
        }
    }
};

export default config;

With that you should get a /build directory that contains index.html. Next just follow the instructions from Cloudflare Pages documentation for deploying your site https://developers.cloudflare.com/pages/framework-guides/deploy-anything/

These instructions include the following:

Deploying with Cloudflare Pages

Deploy your site to Pages by logging in to the Cloudflare dashboard > Account Home > Pages and selecting Create a project. Select the new GitHub repository that you created and, in the Set up builds and deployments section, provide the following information:

Configuration option Value
Production branch main
Build command (optional) <YOUR_BUILD_COMMAND>
Build output directory <YOUR_BUILD_DIR>

Unlike many of the framework guides, the build command and build directory for your site are going to be completely custom. If you do not need a build step, leave the Build command field empty and specify a Build output directory. The build output directory is where your application's content lives.

After configuring your site, you can begin your first deploy. Your custom build command (if provided) will run, and Pages will deploy your static site.

For the complete guide to deploying your first site to Cloudflare Pages, refer to the Get started guide.

After you have deployed your site, you will receive a unique subdomain for your project on *.pages.dev. Cloudflare Pages will automatically rebuild your project and deploy it. You will also get access to preview deployments on new pull requests, so you can preview how changes look to your site before deploying them to production.

From these instructions it looks like you only need to set Production branch to your main branch (or which ever branch you would like deployed) and Build output directory to build (unless otherwise specified in your svelte.config.json). Ensure that your .gitignore does not include the /build directory unless you want to use the Build command config then go ahead and do that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文