Skip to content

Commit

Permalink
Merge pull request #1 from Livshitz/fix-express-example
Browse files Browse the repository at this point in the history
fix express.js example
  • Loading branch information
Livshitz committed May 14, 2024
2 parents 74f63ab + 5c49615 commit fc0148c
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 fc0148c

Please sign in to comment.