From 5c49615dcfa7b4026166bfe0a6bf2af5ce1f23d1 Mon Sep 17 00:00:00 2001 From: Elya Livshitz Date: Tue, 14 May 2024 20:05:50 +0300 Subject: [PATCH] fix express.js example Should be using `createServerAdapter` adapter to convert to express-compatible handler. Based on this issue conversation: https://github.com/kwhitley/itty-router/issues/246#issuecomment-2110506175 --- examples/runtimes/express.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/runtimes/express.js b/examples/runtimes/express.js index 02065846..c7096661 100644 --- a/examples/runtimes/express.js +++ b/examples/runtimes/express.js @@ -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')