-
Notifications
You must be signed in to change notification settings - Fork 0
migrate to cloudflare services #3
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
Open
fusionstrings
wants to merge
17
commits into
creation
Choose a base branch
from
cloudflare
base: creation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2c9ce0f
migrate to cloudflare services
1b64f21
trigger build
bdd66aa
really 🤬
aaac479
add ad-hoc home pagee
d6e13a3
fix link
bce5fb0
actually this is called fixing the link
8746b99
add Promise.race
0567d35
cache fetches
4cc9d2c
improve selection of readme file
3c58fb0
use KV store to improve speed
7e54927
add await
195c27b
use cache control
4b923b1
let's test s-maxage
a69a35e
cache with fetch
56b060c
let's see if this has better performance
7c98f09
clean package.json
427fc0a
moar cache
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { Helmet, jsx, renderSSR } from "nano-jsx"; | ||
import { marked } from "marked"; | ||
import Package from "../../components/package.js"; | ||
|
||
async function customFetch(url, options){ | ||
const response = await fetch(url, options); | ||
if(response.status === 404 || response.status === 500){ | ||
throw new Error(`fetch error on ${url}`); | ||
} | ||
return response; | ||
} | ||
|
||
async function onRequestGet({ params, env, waitUntil }) { | ||
try { | ||
const NPM_PROVIDER_URL = "https://ga.jspm.io/npm:"; | ||
const packageName = params.package.join("/"); | ||
const baseURL = `${NPM_PROVIDER_URL}${packageName}`; | ||
const jspmPackage = await fetch( | ||
`${baseURL}/package.json`, | ||
{ | ||
cf: { | ||
cacheTtlByStatus: { "200-299": 86400, 404: 1, "500-599": 0 }, | ||
}, | ||
}, | ||
) | ||
const readmeFilesToFetch = ["README.md", "readme.md"]; | ||
|
||
const readmeResponse = await Promise.any( | ||
readmeFilesToFetch.map((file) => | ||
customFetch( | ||
`${baseURL}/${file}`, | ||
{ | ||
cf: { | ||
cacheTtlByStatus: { "200-299": 86400, 404: 1, "500-599": 0 }, | ||
}, | ||
}, | ||
) | ||
), | ||
); | ||
|
||
const readmeFileContent = await readmeResponse.text(); | ||
|
||
const readmeHTML = marked.parse(readmeFileContent); | ||
|
||
const { | ||
name, | ||
description, | ||
keywords, | ||
version, | ||
homepage, | ||
license, | ||
files, | ||
exports, | ||
} = await jspmPackage.json(); | ||
|
||
const app = renderSSR( | ||
jsx | ||
`<${Package} name=${name} description=${description} version=${version} homepage=${homepage} license=${license} files=${files} exports=${exports} readme=${readmeHTML} keywords=${keywords} />`, | ||
); | ||
|
||
const { body, head, footer } = Helmet.SSR(app); | ||
|
||
const css = ` | ||
jspm-package-name, jspm-package-version, jspm-package-description, jspm-package-license, jspm-package-file{ | ||
display: block; | ||
} | ||
`; | ||
|
||
const html = ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>${name}@${version} - JSPM</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta name="description" content=${description}> | ||
<style> | ||
${css} | ||
</style> | ||
${head.join("\n")} | ||
</head> | ||
<body> | ||
${body} | ||
${footer.join("\n")} | ||
</body> | ||
</html>`; | ||
|
||
return new Response(html, { | ||
headers: { | ||
"content-type": "text/html; charset=UTF-8", | ||
"Cache-Control": "s-maxage=1500, public, immutable, stale-while-revalidate=1501", | ||
}, | ||
}); | ||
} catch (error) { | ||
console.log(error.stack); | ||
return new Response(`${error.message}`, { status: 500 }); | ||
} | ||
} | ||
|
||
export { onRequestGet }; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do this fetch in parallel with the readme fetch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it here, see if this is what you suggested.
Can be tested at this URL
https://3059f0a9.jspm-packages.pages.dev/package/es-module-shims@1.3.5