我修改了我的Astro Web应用程序以使用SSR(Web应用程序是一个博客,所以我希望博客中的所有帖子都有动态路由)。
似乎该应用程序在我的本地PC上工作正常,但当我试图将其部署到heroku时,它失败了,并出现此错误-
10:09:58 PM [content] No content directory found. Skipping type generation.
10:09:58 PM [build] output target: server
10:09:58 PM [build] deploy adapter: @astrojs/node
10:09:58 PM [build] Collecting build info...
10:09:58 PM [build] Completed in 495ms.
10:09:58 PM [build] Building server entrypoints...
[vite:load-fallback] Could not load @astro-page:astro/assets/endpoint/node (imported by @astrojs-ssr-virtual-entry): The argument 'path' must be a string, Uint8Array, or URL without null bytes. Received '\x00@astro-page:astro/assets/endpoint/node'
error Could not load @astro-page:astro/assets/endpoint/node (imported by @astrojs-ssr-virtual-entry): The argument 'path' must be a string, Uint8Array, or URL without null bytes. Received '\x00@astro-page:astro/assets/endpoint/node'
TypeError [PLUGIN_ERROR]: Could not load @astro-page:astro/assets/endpoint/node (imported by @astrojs-ssr-virtual-entry): The argument 'path' must be a string, Uint8Array, or URL without null bytes. Received '\x00@astro-page:astro/assets/endpoint/node'
at open (node:internal/fs/promises:586:10)
at Object.readFile (node:internal/fs/promises:1044:20)
at Object.load (file:///tmp/build_73de6bf3/node_modules/vite/dist/node/chunks/dep-df561101.js:47019:28)
at async PluginDriver.hookFirstAndGetPlugin (file:///tmp/build_73de6bf3/node_modules/rollup/dist/es/shared/node-entry.js:25439:28)
at async file:///tmp/build_73de6bf3/node_modules/rollup/dist/es/shared/node-entry.js:24606:75
at async Queue.work (file:///tmp/build_73de6bf3/node_modules/rollup/dist/es/shared/node-entry.js:25649:32)
-----> Build failed
字符串
我已经按照指示安装了适配器,如下所示
npm install @astrojs/node
型
在astro.config.mjs中,这是我的配置
import { defineConfig } from 'astro/config';
import vue from "@astrojs/vue";
import node from "@astrojs/node";
// https://astro.build/config
export default defineConfig({
integrations: [vue()],
server: {
host: '0.0.0.0',
port: parseInt(process.env.PORT, 10) || 3000
},
output: 'server',
adapter: node({
mode: "middleware"
})
});
型
这是我的package.json文件
{
"name": "astrowebsite",
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/node": "^6.0.4",
"@astrojs/tailwind": "^5.0.0",
"@astrojs/vue": "^3.0.0",
"@caisy/rich-text-astro-renderer": "^1.0.2",
"@popperjs/core": "^2.11.8",
"@types/bootstrap": "^5.2.7",
"@vueuse/core": "^10.4.1",
"astro": "^3.1.3",
"astro-bootstrap": "^0.6.1",
"axios": "^1.5.1",
"bootstrap": "^5.3.2",
"mdb-vue-ui-kit": "^4.1.0",
"portal-vue": "^3.0.0-beta.0",
"vue": "^3.3.4",
"vue-easy-lightbox": "^1.16.0",
"vue-gallery": "^2.0.5",
"vue-markdown": "^2.2.4"
}
}
型
这是我在应用程序中进行动态路由的方法
const response = await fetch(
"<My heroku url that I do the fetch from>"
);
const { data } = await response.json();
const { slug } = Astro.params;
const page = data.find((project) => project.attributes.title === slug);
if (!page) return Astro.redirect("/404");
const { id, attributes } = page;
型
Heroku提到的那些端点是什么?如何使用SSR连接到那个端点?Heroku服务器框架是nodejs,我不知道如何解决这个问题.我似乎找不到足够的文档,或者从错误中理解我应该做什么。
提前感谢!
1条答案
按热度按时间nimxete21#
我把我的Astro SSR应用程序转移到Vercel,因为Heroku不支持SSR:-)