Update README + deno index
parent
ca0954a310
commit
992df19dd1
14
README.md
14
README.md
|
@ -1,17 +1,17 @@
|
||||||
# Hello middleware for Hono
|
# Sentry middleware for Hono
|
||||||
|
|
||||||
An example project of the third-party middleware for [Hono](https://github.com/honojs/hono).
|
Sentry middleware for [Hono](https://github.com/honojs/hono).
|
||||||
This middleware add `X-Message` header to the Response.
|
This middleware sends captured exceptions to the Sentry data source named by the `SENTRY_DSN` environment variable via [toucan-js](https://github.com/robertcepa/toucan-js).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { hello } from '@honojs/hello'
|
import { sentry } from '@honojs/sentry'
|
||||||
import { Hono } from 'hono'
|
import { Hono } from 'hono'
|
||||||
|
|
||||||
const app = new Hono()
|
const app = new Hono()
|
||||||
|
|
||||||
app.use('*', hello('Hello!! Hono!!'))
|
app.use('*', sentry())
|
||||||
app.get('/', (c) => c.text('foo'))
|
app.get('/', (c) => c.text('foo'))
|
||||||
|
|
||||||
export default app
|
export default app
|
||||||
|
@ -21,12 +21,12 @@ export default app
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { serve } from 'https://deno.land/std/http/server.ts'
|
import { serve } from 'https://deno.land/std/http/server.ts'
|
||||||
import { hello } from 'https://deno.land/x/hono_hello/mod.ts'
|
import { sentry } from 'https://deno.land/x/hono_sentry/mod.ts'
|
||||||
import { Hono } from 'https://deno.land/x/hono/mod.ts'
|
import { Hono } from 'https://deno.land/x/hono/mod.ts'
|
||||||
|
|
||||||
const app = new Hono()
|
const app = new Hono()
|
||||||
|
|
||||||
app.use('*', hello('Hello!! Hono!!'))
|
app.use('*', sentry())
|
||||||
app.get('/', (c) => c.text('foo'))
|
app.get('/', (c) => c.text('foo'))
|
||||||
|
|
||||||
serve(app.fetch)
|
serve(app.fetch)
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
# Hello middleware for Hono
|
# Sentry middleware for Hono
|
||||||
|
|
||||||
An example project of the third-party middleware for [Hono](https://github.com/honojs/hono).
|
Sentry middleware for [Hono](https://github.com/honojs/hono).
|
||||||
This middleware add `X-Message` header to the Response.
|
This middleware sends captured exceptions to the Sentry data source named by the `SENTRY_DSN` environment variable via [toucan-js](https://github.com/robertcepa/toucan-js).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { hello } from '@honojs/hello'
|
import { sentry } from '@honojs/sentry'
|
||||||
import { Hono } from 'hono'
|
import { Hono } from 'hono'
|
||||||
|
|
||||||
const app = new Hono()
|
const app = new Hono()
|
||||||
|
|
||||||
app.use('*', hello('Hello!! Hono!!'))
|
app.use('*', sentry())
|
||||||
app.get('/', (c) => c.text('foo'))
|
app.get('/', (c) => c.text('foo'))
|
||||||
|
|
||||||
export default app
|
export default app
|
||||||
|
@ -21,12 +21,12 @@ export default app
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { serve } from 'https://deno.land/std/http/server.ts'
|
import { serve } from 'https://deno.land/std/http/server.ts'
|
||||||
import { hello } from 'https://deno.land/x/hono_hello/mod.ts'
|
import { sentry } from 'https://deno.land/x/hono_sentry/mod.ts'
|
||||||
import { Hono } from 'https://deno.land/x/hono/mod.ts'
|
import { Hono } from 'https://deno.land/x/hono/mod.ts'
|
||||||
|
|
||||||
const app = new Hono()
|
const app = new Hono()
|
||||||
|
|
||||||
app.use('*', hello('Hello!! Hono!!'))
|
app.use('*', sentry())
|
||||||
app.get('/', (c) => c.text('foo'))
|
app.get('/', (c) => c.text('foo'))
|
||||||
|
|
||||||
serve(app.fetch)
|
serve(app.fetch)
|
||||||
|
|
|
@ -1,8 +1,19 @@
|
||||||
import type { Handler } from 'https://raw.githubusercontent.com/honojs/hono/v2.0.6/deno_dist/mod.ts'
|
import type { Handler } from 'https://raw.githubusercontent.com/honojs/hono/v2.0.6/deno_dist/mod.ts'
|
||||||
|
import Toucan from 'toucan-js'
|
||||||
|
|
||||||
export const hello = (message: string = 'Hello'): Handler => {
|
export const hello = (): Handler => {
|
||||||
return async (c, next) => {
|
return async (c, next) => {
|
||||||
await next()
|
const sentry = new Toucan({
|
||||||
c.res.headers.append('X-Message', message)
|
dsn: c.env.SENTRY_DSN,
|
||||||
|
request: c.req,
|
||||||
|
allowedHeaders: ['user-agent'],
|
||||||
|
allowedSearchParams: /(.*)/,
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await next()
|
||||||
|
} catch (error) {
|
||||||
|
sentry.captureException(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue