You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deno fetch gives error (TLS related, and origin is rust library)
Using fetch in Lume v2.4.2 (a Deno Typescript static site generator app) on Deno 2.1.2, I get this error when fetching to our ops db REST API:
fetch TypeError: "client error connection reset by peer"
I see a lot of people have had this same problem, in various GH issues, and it appears that it is because of the underlying Rust library being used. For example:
I naively tried an alternative to fetch, ky, which I thought might do something magical, but no, since I tried it in Deno, it's using Deno's fetch underneath, in the end. Pasted test code below for posterity. (I must say, ky really simplifies this type of code; nice library!)
Resolution: curl-based workaround in Lume beforeBuild script
Lume runs on Deno and since Deno is probably not going to easily be able to change the library their fetch uses easily (to, say, openssl) then how can we work around it?
Lume allows you to run scripts before and after the site build, in _config.ts, so the venerable curl comes to our rescue:
...
// Prepare script to get holidays from dbflexsite.script("getholidays","cd src/_data && curl -H \"Authorization: Bearer ${API_KEY_01}\" https://pro.dbflex.net/secure/api/v2/15331/Work%20Holiday/API%20Holidays%20Today%20or%20Later/select.json -o futureholidays.json");// Execute scripts before buildsite.addEventListener("beforeBuild","getholidays");
...
exportdefaultsite;
The ${API_KEY_01} is the key we need to access the database's REST i/f, and I have it set locally and in Github environment variables. Note, in the context of setting a secret for Github Actions, I found that this must be set in Settings, Security, Secrets and Variables, Actions, Repository Secrets, not "environment" Secrets.
Assuming the secret name is MYKEY, pull it into your build step in the Github workflow like so:
- name: Build site# Run the build script from deno.jsonenv:
API_KEY_01: ${{ secrets.MYKEY }}run: deno task build
This curl script pulls the data into a file prior to build, src/_data/futureholidays.json, which Lume then sets up as an object that can be accessed in Vento templates, during the build. Full workflow action below, and if the secret is being evaluated correctly, you can see the value as *** (as expected) in the GH action run log:
[
...
{
"@row.id": 477,
Date: "2024-12-29T00:00:00+00:00","Date in YYYYMMDD": "20241229",
"Date in YYYY-MM-DD": "2024-12-29",
"Day of Week": "Sunday",
"Date with Month Name": "29 Dec 2024",
Name: "Year End Holiday","Name Jp": "年末休み"
},
{
"@row.id": 476,
Date: "2024-12-28T00:00:00+00:00","Date in YYYYMMDD": "20241228",
"Date in YYYY-MM-DD": "2024-12-28",
"Day of Week": "Saturday",
"Date with Month Name": "28 Dec 2024",
Name: "Year End Holiday","Name Jp": "\t年末休み"
}
...
]
In our Vento template, since Vento supports js, we want to match on today's date, find the node with that date (we assume one entry per date), and use javascript filter and map in the following way:
{{setmatchdate=todaysDateYYYYMMDD}}{{setmatchholi=futureholidays.filter(item=>item['Date in YYYY-MM-DD']===matchdate)}}{{ifmatchholi.length>0}}**It's a holiday in Japan:**
{{ set resultholi=matchholi.map(item=>item['Name'])+" / "+matchholi.map(item=>item['Name Jp'])}}{{ resultholi }}{{/if}}
The Vento template code is doing:
set a variable to today's date, in the right format to match in the json
using filter to find the json node where today's date matches the date in the node
if there was a match, return some markdown text "It's a holiday..."
prepare the string as a concatenation of the json node's English and Japanese names, using map to find the sibling to the matched date
return the string to the page
The todaysDateYYYYMMDD constant is prepared by Lume from /src/_data.ts as follows:
Per this issue I tried running deno with the --unsafely-ignore-certificate-errors flag, but after trying to fetch directly to my PaaS DB REST i/f, I still get the same error.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters