Update README + deno index

pull/31/head
Samuel Lippert 2022-08-09 11:08:36 -05:00
parent ca0954a310
commit 992df19dd1
No known key found for this signature in database
GPG Key ID: 3762857AF8948B2C
3 changed files with 28 additions and 17 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)
}
} }
} }