aquametalabs / aquameta

Web development platform built entirely in PostgreSQL
GNU General Public License v3.0
1.1k stars 52 forks source link

Resource functions should return custom headers #262

Closed micburks closed 1 year ago

micburks commented 1 year ago

Scenario: I have two endpoint.resource_functions. They both return a javascript resource. One returns the dev version (the active row that can be changed anytime) and the other function returns an immutable module that can be cached forever. However, if the immutable javascript module doesn't exist, I want to fallback to returning the dev version.

widget.dev_version() {
  return SELECT js from ...;
}
widget.cached_version() {
  if (EXISTS ...) {
    return SELECT cached_js from ...;
  } else {
    return widget.dev_version();
  }
}

The headers cannot be a field in endpoint.resource_function because we don't want to cache the fallback dev version.

Rather, we can return a record from the resource function

select content, headers from your_function(...) as (content text, headers jsonb)
micburks commented 1 year ago

Fixed #269 on 0.4