Replies: 3 comments 4 replies
-
Hi @sher It can't pass the custom not found handler to const main = new Hono()
const api = new Hono()
api.get('/', (c) => c.json('/'))
api.get('/abc', (c) => c.json('abc'))
api.get('*', (c) => c.text('Custom 404 Message from API', 404))
main.route('/api', api) |
Beta Was this translation helpful? Give feedback.
-
Thanks @yusukebe I didn't explain the full context. Hono app is deployed and serving rest api on prefix app.route('/api', api);
app.get('/assets/*', serveStatic({ root: './', manifest }));
app.get('/favicon.ico', serveStatic({ path: './favicon.ico', manifest }));
app.get('*', async function (c, next) {
if (c.req.path.startsWith('/api/')) {
return c.json(undefined, 404);
}
return serveStatic({ path: './index.html', manifest })(c, next);
}); |
Beta Was this translation helpful? Give feedback.
-
IMHO, this should just work: import { serve } from "@hono/node-server";
import { Hono } from "hono";
const app = new Hono();
app.notFound((c) => c.text("App Not Found", 404));
const sub = new Hono();
sub.notFound((c) => c.text("Sub Not Found", 404));
app.route("/sub", sub);
serve({ fetch: app.fetch }); However, I get |
Beta Was this translation helpful? Give feedback.
-
Given a simple app with grouped routes:
What I am trying to achieve:
/api/*
requests fromapi
module/api/*
pattern, but endpoint handler is missing, respond withapi.notFound
handlerGET
requests serve a staticindex.html
But what really is happening is that
/api/missing-endpoint
URL is also servingmain.get('*', ...)
handler, which is a staticindex.html
Beta Was this translation helpful? Give feedback.
All reactions