我有一个AstroJS项目,这是我的astro.config.mjs:

import tailwind from "@astrojs/tailwind";
import vue from '@astrojs/vue';
import sanity from "@sanity/astro";
import { defineConfig } from 'astro/config';
import { sanityClientConfigWithCdn } from './const';
import node from '@astrojs/node';

export default defineConfig({
  output: 'hybrid',
  adapter: node({
    mode: 'standalone',
  }),
  integrations: [
    tailwind(), 
    sanity(sanityClientConfigWithCdn), 
    vue({appEntrypoint: "/src/vue.ts"}),
  ]
});

下面是我的测试API终结点:

import type { APIRoute } from "astro";

export const prerender = false;

export const GET: APIRoute = async ({ params, request }) => {
  return new Response(JSON.stringify({
    message: "TEST"
  }))
}

最后是我的页面文件 struct :

├── api
│   └── test.ts
└── [...lang]
    ├── index.astro
    └── news.astro

我收到此错误/警告:

06:49:15 PM [getStaticPaths] A `getStaticPaths()` route pattern was matched, but no matching static path was found for requested path `/404`.

Possible dynamic routes being matched: src/pages/[...lang]/index.astro.
06:49:15 PM [serve]    404                                     /404

起初我认为[...lang]动态路由是问题所在.但是,我仍然得到404即使删除整个目录.我正在执行npm run dev并try 访问http://localhost:3000/api/test(这是正确的主机和端口).有什么问题吗?

推荐答案

事实证明,我确实需要升级我的AstroJS版本.使用过时的AstroJS版本的一个副作用是,我正在安装一个过时的@astrojs/node,所以可能这也会导致一个问题.因此,相同的文件 struct ,相同的代码,相同的一切,除了从天文版本,它现在的工作如预期.

Javascript相关问答推荐

当promise 在拒绝处理程序被锁定之前被拒绝时,为什么我们会得到未捕获的错误?

如何最好地从TypScript中的enum获取值

窗口.getComputedStyle()在MutationObserver中不起作用

过滤对象数组并动态将属性放入新数组

字节数组通过echo框架传输到JS blob

如何解决CORS政策的问题

如何在Javascript中的控制台上以一行形式打印循环的结果

如何通过使用vanilla JS限制字体大小增加或减少两次来改变字体大小

Eval vs函数()返回语义

有条件重定向到移动子域

如何在Svelte中从一个codec函数中调用error()?

Reaction Redux&Quot;在派单错误中检测到状态Mutations

第一项杀死下一项,直到数组长度在javascript中等于1

在Vercel中部署Next.js项目时获取`ReferenceError:未定义文档`

Django导入问题,无法导入我的应用程序,但我已在设置中安装了它

如果NetSuite中为空,则限制筛选

Angel Auth Guard-用户只有在未登录时才能访问登录页面,只有在登录时才能访问其他页面

如何将对象推送到firestore数组?

无法向甜甜圈图表上的ChartJSImage添加可见标签

如何根据获取的对象数量动态生成状态变量