#hono error

1 messages · Page 1 of 1 (latest)

abstract hinge
#

api/[...path}.ts
import { Hono } from "hono";

import type { APIRoute } from "astro";

// ...

export const ALL: APIRoute = () => new Response("Hello World");
error:
Hint:
See https://docs.astro.build/en/guides/routing/#dynamic-routes for more information on dynamic routes.

Alternatively, set `output: "server"` or `output: "hybrid"` in your Astro config file to switch to a non-static server build. This error can also occur if using `export const prerender = true;`.
See https://docs.astro.build/en/guides/server-side-rendering/ for more information on non-static rendering.

Error reference:
https://docs.astro.build/en/reference/errors/get-static-paths-required/
Stack trace:
at A:\new-website\src\pages\api[...path].ts
[...] See full stack trace in the browser, or rerun with --verbose.

nocturne warrenBOT
#

Hi @abstract hinge. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The error you're encountering is related to the use of dynamic routes in Astro. In Static Mode, all routes must be determined at build time. Therefore, dynamic routes must export a getStaticPaths function that returns the different paths to generate.

Your current file api/[...path}.ts seems to be missing this function. Here's an example of how you might define it:

export function getStaticPaths() {
  return [
    {params: {path: 'one/two/three'}},
    {params: {path: 'four'}},
    {params: {path: undefined }}
  ]
}

In this example, getStaticPaths returns an array of objects, each containing a params object that corresponds to the dynamic parts of the route.

If you don't want to predefine all possible routes at build time, you can switch to Server-side Rendering (SSR) mode by setting output: "server" or output: "hybrid" in your Astro config file. In SSR mode, dynamic routes are served to any matching route and getStaticPaths should not be used.

For more information, you can refer to the following guides:

And here is the specific error reference:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@abstract hinge kapa.ai is still learning and improving, please let us know how it did by reacting below

abstract hinge
#

@nocturne warren can you fix it?
import { Hono } from "hono";

import type { APIRoute } from "astro";

// ...

export const ALL: APIRoute = () => new Response("Hello World");

nocturne warrenBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Based on the code you've provided and the error message, it seems like you're trying to use a dynamic route in Astro's static mode. To fix this, you need to define a getStaticPaths function that returns the different paths to generate. However, the getStaticPaths function is not applicable in your case because you're defining an API route, not a page route.

If you want to keep using the static mode, you might need to define specific routes for your API instead of using a dynamic route.

However, if you want to use dynamic routes for your API, you should switch to Server-side Rendering (SSR) mode by setting output: "server" or output: "hybrid" in your Astro config file. In SSR mode, a page will be generated on request for any route that matches, and getStaticPaths should not be used.

Here's how you can switch to SSR mode:

// astro.config.mjs
export default {
  output: 'server',
  // ...
}

After making this change, your existing API route should work as expected without needing to define getStaticPaths.

For more information, please refer to the Astro documentation on Server-side Rendering (https://docs.astro.build/en/guides/server-side-rendering/) and Dynamic Routes (https://docs.astro.build/en/guides/routing/#dynamic-routes).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: