Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty env object in templates #85

Closed
karthik2804 opened this issue Jul 19, 2022 · 3 comments
Closed

Empty env object in templates #85

karthik2804 opened this issue Jul 19, 2022 · 3 comments

Comments

@karthik2804
Copy link
Contributor

The env object is missing data about the HTTP request, the path of this resource, and other Spin information in contradiction to the documentation. The only key-value pairs present in it are the environment variables set if any.

Steps to reproduce:

  • Fresh copy of Bartholomew.
  • replace docs/templates/main.hbs to just print the env object
  • run spin up -env PREVIEW_MODE=1

main.hbs:

<ul>
    {{#each env}}
    <li><code>{{@key}}</code>: <code>"{{this}}"</code></li>
    {{/each}}
</ul>

expected result:

{
    PREVIEW_MODE: "1"
    HTTP_REQ: "..."
    PATH: "..."
    SPIN: "..."
}

obtained result:

{
    PREVIEW_MODE: "1"
}

The lack of HTTP request and PATH data limit the amount of dynamic generation that can be done. For example, Pagination of content would require path information.

@radu-matei
Copy link
Member

That information was historically passed into Bartholomew as environment variables because of the CGI spec and Wagi.

Since moving Bartholomew to be a Spin component, most of that information is now passed as headers — see https://spin.fermyon.dev/http-trigger/

@karthik2804
Copy link
Contributor Author

karthik2804 commented Jul 19, 2022

Thanks for pointing to the resource.

As a follow-up, I see a request object which is currently passed as an empty object to TemplateContext, would this be the right place to add the information?

If so what are the fields that would need to be added to the request object? Based on the default headers that are passed from spin, only the spin-full-path would be needed as the rest can be obtained from the full path. What others would be suggested to be implemented. I can work on submitting a PR once the implementation is discussed.

Once the headers are accessible from the templates, pagination will be possible using the URL query parameters.

Any inputs would be greatly appreciated!

karthik2804 added a commit to karthik2804/bartholomew that referenced this issue Jul 21, 2022
Signed-off-by: Karthik Ganeshram <kganeshram@ucdavis.edu>
karthik2804 added a commit to karthik2804/bartholomew that referenced this issue Jul 22, 2022
Signed-off-by: Karthik Ganeshram <kganeshram@ucdavis.edu>
@karthik2804
Copy link
Contributor Author

Fixed by #90

vdice added a commit that referenced this issue Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants