Replies: 2 comments
-
does anyone maintain this discussion page? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm having the same problem and can't get the example Hono project https://hono.dev/docs/ to debug with breakpoints. As a workaround, I'm using @hono/node-server as a second option and launching it with "Debug Hono with Node" when I need debugging. Hope someone has an example of successfully debugging without node-server. My example with @hono/node-server as second option: server.js import { OpenAPIHono } from '@hono/zod-openapi'
import { logger } from 'hono/logger'
import { authenticateToken } from './middleware/auth'
import { securityHeaders } from './middleware/security'
import { corsMiddleware } from './middleware/cors'
import { errorHandler } from './middleware/errorHandler'
import publicRoutes from './routes/public'
import apiRoutes from './routes/api'
import { setupSwagger } from './config/swagger'
// Create a typed Hono instance
const app = new OpenAPIHono()
// Global middleware
app.use('*', errorHandler)
app.use('*', corsMiddleware)
app.use('*', logger())
app.use('*', securityHeaders)
// Setup Swagger documentation
setupSwagger(app)
// Mount routes
app.route('/', publicRoutes)
//Protected routes
app.use('/api/*', authenticateToken)
app.route('/api', apiRoutes)
// 404 handler for routes that don't exist
app.notFound((c) => {
return c.json({
error: `Route '${c.req.path}' not found`,
status: 404
}, 404)
})
// For Bun
export default {
port: 8002,
fetch: app.fetch
}
// For Node.js
if (process.env.npm_lifecycle_event === 'dev:node') {
import('@hono/node-server').then(({ serve }) => {
serve({
fetch: app.fetch,
port: 8002
}, (info) => {
console.log(`Server is running on http://localhost:${info.port}`)
})
})
} package.js {
"name": "hono",
"scripts": {
"dev": "bun run --hot src/index.ts",
"dev:node": "tsx watch --inspect src/index.ts",
"db:generate": "bunx --bun drizzle-kit generate:pg",
"db:migrate": "bun run src/db/migrate.ts"
},
"dependencies": {
"@hono/swagger-ui": "^0.5.0",
"@hono/zod-openapi": "^0.18.4",
"@hono/zod-validator": "^0.4.3",
"@supabase/supabase-js": "^2.48.1",
"@types/memory-cache": "^0.2.6",
"@types/pg": "^8.11.11",
"dotenv": "^16.4.7",
"drizzle-orm": "^0.39.3",
"hono": "^4.7.1",
"memory-cache": "^0.2.0",
"pg": "^8.13.3",
"zod": "^3.24.2"
},
"devDependencies": {
"@hono/node-server": "^1.13.8",
"@types/bun": "latest",
"drizzle-kit": "^0.30.4",
"tsx": "^4.7.1"
}
} launch.json {
"version": "0.2.0",
"configurations": [
{
"name": "backend",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "dev"],
"cwd": "${workspaceFolder}/backend",
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**"
]
},
{
"name": "frontend",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}/frontend",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "dev"],
"console": "integratedTerminal"
},
{
"name": "Debug Hono with Node",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "dev:node"],
"cwd": "${workspaceFolder}/backend",
"skipFiles": ["<node_internals>/**"],
"console": "integratedTerminal"
},
{
"name": "Debug Hono with Bun --BREAKPINTS NOT WORKING",
"type": "node",
"request": "launch",
"runtimeExecutable": "bun",
"runtimeArgs": ["--inspect", "src/index.ts"],
"cwd": "${workspaceFolder}/backend",
"skipFiles": ["<node_internals>/**"],
"console": "integratedTerminal"
}
],
"compounds": [
{
"name": "Full Stack",
"configurations": ["backend", "frontend"]
}
]
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
using honojs with openAPI, normally we have a launch.json file in projec/.vscode file and can debug any file using breakpoint but when running hono application and want to attach a debugger to stop and see the request response within vscode debug optons ( vs code v 1.95 in ubuntu 24.04 with node v 22)
here are my 3 different kind of launch,json configuration; none of them not working as expected.
"Debug Hono with tsx
script run s but it does not stop at given breakpoint and also do some changes in package.json script for this but does not workAttch
script script attach but when add breakpoint it say outbound brerakpoint inm vsode.vscode/launch.json
what I want is when run
npm run start
it should attach the debugger and I have index.tsx file is main filepackage.json script part
tsconfig.json
Beta Was this translation helpful? Give feedback.
All reactions