h3-express
v0.3.0
Published
Express polyfill for h3
Downloads
724
Readme
h3-express
Express polyfill for h3.
By default, Body-parsing is enabled. Therefore, query, body, params and cookie fields can be used without the following middlewares.
- express.urlencoded,
- express.json
- express.raw
- express.text
- express.cookies.
define a handler
import { defineExpressHandler } from 'h3-express'
export default defineExpressHandler((req, res) => {
req.json({
req.path,
req.query,
req.body,
req.params,
req.cookies,
})
})
define a middleware
import { defineExpressHandler } from 'h3-express'
import session from 'express-session'
export default defineExpressHandler(session({
...
}))
define a compound middleware
import { defineExpressHandler } from 'h3-express'
import express from 'express'
import session from 'express-session'
import fileupload from 'express-fileupload'
export default defineExpressHandler(express.Router()
.use(session({
...
}))
.use(fileupload({
...
}))
)
get h3 event
import { defineExpressHandler, getH3Event } from 'h3-express'
export default defineExpressHandler((req, res) => {
const event = getH3Event(req)
req.end()
})