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

Feature/issue 1048 handle merging additional `Request` / `Response` properties #1132

Closed thescientist13 closed 1 year ago

thescientist13 commented 1 year ago

Related Issue

resolves #1048

Depends on #1131

Summary of Changes

  1. Honor and merge all constructor options for Response
  2. Honor body (.text(), .json() and formData()) and method on Request objects
  3. "Lock down" content type header responses in test cases (Found that internal Font Resource plugin was not returning the correct content type - worth making a new issue?)
  4. Added new test cases

TODO

  1. [x] Merge all applicable Request properties- https://github.com/thescientist13/greenwood-htmx/pull/3
    • body
    • headers
    • query params
    • Others? - see Thoughts section below
  2. [x] Merge all applicable Response properties
    • status
    • statusText ?
  3. [x] Apply to all instance in serve lifecycle
    • return all header, like custom x-secret header in the POST /api/submit example in develop
  4. [x] executeRouteModule
    • API Routes
    • SSR page - I think the plan is to support this in #952 ?
  5. [x] Apply to Adapter plugins
    • 1128

    • 1139

  6. [x] Apply to SSR page bundled output? - https://github.com/ProjectEvergreen/greenwood/blob/v0.29.0-alpha.1/packages/cli/src/lifecycles/bundle.js#L224
  7. [x] Add test cases
  8. [x] POST w/ request.formData
    • and adapter plugins
  9. [x] Clean up console logs
  10. [x] Clean up TODO items
    • issues/1048
    • issues/1008
  11. [ ] Documentation updates?
  12. [ ] ~~multipart/form-data~~ support (nice to have)? - https://github.com/ProjectEvergreen/greenwood/issues/1147

Thoughts / Questions

  1. [x] We don't get much from each ctx.request from Koa, so we can't really flesh out more than this from an initial request. Not sure how much of a Request options is ultimately worth merging on or we can even support? Maybe a good discussion topic? - https://github.com/ProjectEvergreen/greenwood/discussions/1146
    CTX.REQUEST {
      method: 'GET',
      url: '/api/missing',
      header: { host: '127.0.0.1:8080', connection: 'close' }
    }
  2. [x] Could maybe add a tracking issue to validate all body options. Not sure how to best handle / detect them in Koa for serialization though? Options like: - https://github.com/ProjectEvergreen/greenwood/issues/1147
    • URLSearchParams
    • Blob