2021-12-17 09:16:26 +01:00
|
|
|
const Hono = require('../../src/hono')
|
|
|
|
const app = Hono()
|
2021-12-15 03:41:28 +01:00
|
|
|
|
2021-12-17 09:16:26 +01:00
|
|
|
app.get('/', () => 'Hono!!')
|
|
|
|
app.get('/hello', () => 'This is /hello')
|
|
|
|
|
|
|
|
app.fire()
|
2021-12-20 03:19:35 +01:00
|
|
|
|
|
|
|
const router = app.router()
|
|
|
|
|
|
|
|
router.get('/:id', (req, res) => {
|
|
|
|
req.query
|
|
|
|
req.params
|
|
|
|
res.status(200).json({ message: 'hello' })
|
|
|
|
})
|
|
|
|
|
|
|
|
app.use('/', router)
|
|
|
|
app.all('/', router)
|
|
|
|
|
|
|
|
const logger = (req) => {
|
|
|
|
const url = req.newURL
|
|
|
|
console.log(req.url.pathname)
|
|
|
|
}
|
|
|
|
|
|
|
|
app.get('/hello', logger, (req) => {
|
|
|
|
const message = body.URLSearchParams.get('message')
|
|
|
|
const res = req.newResponse()
|
|
|
|
res.json({ message: message })
|
|
|
|
return res
|
|
|
|
})
|
|
|
|
|
|
|
|
app.handle({ method: 'GET', path: '/hello?message=hello' })
|
|
|
|
|
|
|
|
Application
|
|
|
|
Router
|