Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 0 additions & 3 deletions css/style.css

This file was deleted.

110 changes: 0 additions & 110 deletions deploy.js

This file was deleted.

25 changes: 0 additions & 25 deletions dom/main.js

This file was deleted.

1 change: 0 additions & 1 deletion functions/main.js

This file was deleted.

100 changes: 100 additions & 0 deletions functions/package/[[package]].js
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(

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?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`${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 };
31 changes: 0 additions & 31 deletions functions/remove-slash.js

This file was deleted.

24 changes: 0 additions & 24 deletions importmap-generator.js

This file was deleted.

10 changes: 5 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
<h1>@jspm/packages / Home Page</h1>
<nav>
<ul>
<li><a href="packages">packages</a></li>
<li><a href="packages/es-module-shims">es-module-shims</a></li>
<li><a href="packages/@jspm/generator">@jspm/generator</a></li>
<li><a href="packages/react">react</a></li>
<li><a href="/">packages</a></li>
<li><a href="package/es-module-shims@1.3.5">es-module-shims</a></li>
<li><a href="package/@jspm/generator@1.0.0-beta.19">@jspm/generator</a></li>
<li><a href="package/react@17.0.2">react</a></li>
</ul>
</nav>
</main>
</body>

</html>
</html>
Loading