Skip to content

Commit

Permalink
fix express.js example (#247)
Browse files Browse the repository at this point in the history
Should be using `createServerAdapter` adapter to convert to express-compatible handler.
Based on this issue conversation: #246 (comment)
  • Loading branch information
Livshitz committed May 14, 2024
1 parent 74f63ab commit f4d79f0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions examples/runtimes/express.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import express from 'express'
import { Router, error, json } from 'itty-router'
import 'isomorphic-fetch'
import { createServerAdapter } from '@whatwg-node/server'

const app = express()

const router = Router()

router.get('/', () => 'Success!').all('*', () => error(404))
router.get('/', () => 'Success!')
router.all('*', () => error(404))

const handle = (request) => router.handle(request).then(json).catch(error)
const handle = (request) => router.fetch(request).then(json).catch(error)

app.use(handle)
const ittyServer = createServerAdapter(handle)
app.use(ittyServer.handle)

app.listen(3001)
console.log('listening at https://localhost:3001')

0 comments on commit f4d79f0

Please sign in to comment.