ProjectEvergreen / greenwood

Greenwood is your workbench for the web, embracing web standards from the ground up to empower your stack from front to back.
https://www.greenwoodjs.io
MIT License
96 stars 9 forks source link

minimal `Response` throws errors in development and production lifecycles #1130

Closed thescientist13 closed 1 year ago

thescientist13 commented 1 year ago

Type of Change

Bug

Summary

Noticed that if you have even just a minimalist Response object, say for an API endpoint

export async function handler() {
  return new Response(undefined);
}

you will get an exception in the CLI for development

TypeError: Cannot read properties of null (reading 'indexOf')
    at LiveReloadResource.shouldIntercept (file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/plugins/server/plugin-livereload.js:57:24)
    at file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/lifecycles/serve.js:107:52
    at async file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/lifecycles/serve.js:105:24
    at async file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/lifecycles/serve.js:90:5
    at async file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/lifecycles/serve.js:54:5

or this for production

      Serve command with API specific behaviors with a minimal response
TypeError [ERR_INVALID_ARG_TYPE]: The "iterable" argument must be an instance of Iterable. Received null

Details

Looks to be caused by many assumptions of a particular header to be defined already in Resource plugin intercept lifecycles 🤦

async shouldIntercept(url, request, response) {
  return response.headers.get('Content-Type').indexOf('text/html') >= 0;
}