kwhitley / itty-router

A little router.
MIT License
1.75k stars 78 forks source link

Failed to execute function parameter 1 is not of type response #63

Closed janat08 closed 2 years ago

janat08 commented 2 years ago

If you respond with html not using the router then you don't get the error. I still get html in the preview, but the stackstraces are really annoyining in terminal. Everything works but with stack traces in terminal. I believe it will still show underlying errors like reference errors and stuff but you have to scroll more.

import { Router } from 'itty-router'
import {html, HTMLResponse} from '@worker-tools/html'
import {layout} from "./views/layout.js"
import paypal from './paypal.js'
const router = Router()
router.get('/', function handleRequest(event) {
  const page = html`
    abc  `
  return new HTMLResponse (layout(page));
})
router.all('/paypal/*', paypal.fetch)

addEventListener('fetch', event =>
event.respondWith(new HTMLResponse (layout(html`abc  `)))
  // event.respondWith(router.handle(event.request))
)

layoutjs

import {html, HTMLResponse} from '@worker-tools/html'

export function layout (content, title = "Source Domains") {
  return html`
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>${title}</title>
  </head>
  <body>${content}</body>
</html>
`;}

export default function render (content, title = "Source Domains"){
  return new HTMLResponse(layout(content, title))
}
kwhitley commented 2 years ago

A few things here:

Closing this as not an issue until you're able to provide more details about the routes being fed through this, and other missing parts like what paypal.fetch entails.