0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-22 11:17:33 +01:00
hono/example/basic/index.js
2021-12-21 08:02:20 +09:00

24 lines
493 B
JavaScript

const Hono = require('../../src/hono')
const app = Hono()
// 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!')
}
// Mount middleware
app.use('*', logger)
app.use('/hello', addHeader)
// Routing
app.get('/', () => new Response('Hono!!'))
app.get('/hello', () => new Response('This is /hello'))
// addEventListener
app.fire()