Toucan reference not valid for Deno

pull/31/head
Samuel Lippert 2022-08-09 11:32:06 -05:00
parent 992df19dd1
commit 9dc53e6428
No known key found for this signature in database
GPG Key ID: 3762857AF8948B2C
2 changed files with 17 additions and 19 deletions

View File

@ -1,19 +1,18 @@
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 = (): Handler => {
export const sentry = (): Handler => {
return async (c, next) => {
const sentry = new Toucan({
dsn: c.env.SENTRY_DSN,
request: c.req,
allowedHeaders: ['user-agent'],
allowedSearchParams: /(.*)/,
})
// const sentry = new Toucan({
// dsn: c.env.SENTRY_DSN,
// request: c.req,
// allowedHeaders: ['user-agent'],
// allowedSearchParams: /(.*)/,
// })
try {
await next()
} catch (error) {
sentry.captureException(error)
}
// try {
await next()
// } catch (error) {
// sentry.captureException(error)
// }
}
}

View File

@ -1,15 +1,14 @@
import { hello } from '../deno_dist/mod.ts'
import { sentry } from '../deno_dist/mod.ts'
import { assertEquals, Hono } from './deps.ts'
// Test just only minimal patterns.
// Because others are tested well in Cloudflare Workers environment already.
Deno.test('Hello Middleware', async () => {
Deno.test('Sentry Middleware', async () => {
const app = new Hono()
app.use('/hello/*', hello())
app.get('/hello/foo', (c) => c.text('foo'))
app.use('/sentry/*', sentry())
app.get('/sentry/foo', (c) => c.text('foo'))
let res = await app.request('http://localhost/hello/foo')
const res = await app.request('http://localhost/sentry/foo')
assertEquals(res.status, 200)
assertEquals(res.headers.get('X-Message'), 'Hello')
})