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-20 18:35:03 +01:00
|
|
|
// Middleware
|
|
|
|
const logger = (req, _, next) => {
|
|
|
|
console.log(`[${req.method}] ${req.url}`)
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
const addHeader = (_, res, next) => {
|
|
|
|
next()
|
|
|
|
res.headers.append('X-message', 'This is addHeader middleware!')
|
|
|
|
}
|
2021-12-20 03:19:35 +01:00
|
|
|
|
2021-12-20 18:35:03 +01:00
|
|
|
app.use('*', logger)
|
|
|
|
app.use('/hello', addHeader)
|
2021-12-20 03:19:35 +01:00
|
|
|
|
2021-12-20 18:35:03 +01:00
|
|
|
// Routing
|
|
|
|
app.get('/', () => {
|
|
|
|
return new Response('Hono!!')
|
2021-12-20 03:19:35 +01:00
|
|
|
})
|
2021-12-20 18:35:03 +01:00
|
|
|
app.get('/hello', () => {
|
|
|
|
return new Response('This is /hello')
|
2021-12-20 03:19:35 +01:00
|
|
|
})
|
|
|
|
|
2021-12-20 18:35:03 +01:00
|
|
|
// addEventListener
|
|
|
|
app.fire()
|