parent
f7d6fb0d95
commit
5cd86dd5d7
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@honojs/hello': patch
|
||||
---
|
||||
|
||||
the repository has been moved
|
|
@ -0,0 +1,26 @@
|
|||
# Hello middleware for Hono
|
||||
|
||||
An example project of the third-party middleware for [Hono](https://github.com/honojs/hono).
|
||||
This middleware add `X-Message` header to the Response.
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { hello } from '@honojs/hello'
|
||||
import { Hono } from 'hono'
|
||||
|
||||
const app = new Hono()
|
||||
|
||||
app.use('*', hello('Hello!! Hono!!'))
|
||||
app.get('/', (c) => c.text('foo'))
|
||||
|
||||
export default app
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
Yusuke Wada <https://github.com/yusukebe>
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
|
@ -0,0 +1 @@
|
|||
module.exports = require('../../jest.config.js')
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "@honojs/hello",
|
||||
"version": "0.0.6",
|
||||
"description": "An example of third-party middleware for Hono",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"build": "rimraf dist && tsc",
|
||||
"prerelease": "yarn build && yarn test",
|
||||
"release": "yarn publish"
|
||||
},
|
||||
"license": "MIT",
|
||||
"private": false,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/honojs/middleware.git"
|
||||
},
|
||||
"homepage": "https://github.com/honojs/middleware",
|
||||
"dependencies": {
|
||||
"hono": "^2.2.5"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
import { Hono } from 'hono'
|
||||
import { hello } from '../src'
|
||||
|
||||
describe('Hello middleware', () => {
|
||||
const app = new Hono()
|
||||
|
||||
app.use('/hello/*', hello())
|
||||
app.get('/hello/foo', (c) => c.text('foo'))
|
||||
|
||||
app.use('/x/*', hello('X'))
|
||||
app.get('/x/foo', (c) => c.text('foo'))
|
||||
|
||||
it('Should be hello message', async () => {
|
||||
const res = await app.request('http://localhost/hello/foo')
|
||||
expect(res).not.toBeNull()
|
||||
expect(res.status).toBe(200)
|
||||
expect(res.headers.get('X-Message')).toBe('Hello')
|
||||
})
|
||||
|
||||
it('Should be X', async () => {
|
||||
const res = await app.request('http://localhost/x/foo')
|
||||
expect(res).not.toBeNull()
|
||||
expect(res.status).toBe(200)
|
||||
expect(res.headers.get('X-Message')).toBe('X')
|
||||
})
|
||||
})
|
|
@ -0,0 +1,8 @@
|
|||
import type { Handler } from 'hono'
|
||||
|
||||
export const hello = (message: string = 'Hello'): Handler => {
|
||||
return async (c, next) => {
|
||||
await next()
|
||||
c.res.headers.append('X-Message', message)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
}
|
Loading…
Reference in New Issue