1import { prettifyHtml } from "https://esm.town/v/neverstew/prettifyHtml";
2import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=6";
3import { escape } from "npm:html-sloppy-escaper";
4
5export default async function viewSource(req: Request) {
6 const pathname = new URL(req.url).pathname;
7 const html = await fetchText(pathname === "/" ? "example.com" : pathname).then(prettifyHtml);
8 const body = `<html>
9 <head>
9 setItems([...items]);
10
11 // fetch data from the server
12 fetch("/api/item")
13 .then((res) => res.json())
14 .then((item) => setItems([...items, item]));
30 const url = new URL(req.url);
31 if (url.pathname == "/api/item") {
32 return Response.json("This item is fetched from the server by the client");
33 }
34
10 if (hash.startsWith("0x0")) {
11 const hash = new URL(url).pathname.split("/").pop();
12 const urlStream = await fetch(`https://api.blobscan.com/blobs/${hash}`);
13 const arrayBuffer = await urlStream.arrayBuffer();
14 const blob = new Blob([arrayBuffer], { type: "application/json" });
16 data.append("file", file);
17 } else {
18 const tx = await fetch(`https://api.blobscan.com/transactions/${hash}`);
19 const txData = await tx.json();
20
22 let folder = "blobs"
23 await Promise.all(txData.blobs.map(async (blob, index) => {
24 const blobStream = await fetch(`https://api.blobscan.com/blobs/${blob}`);
25 const arrayBuffer = await blobStream.arrayBuffer();
26 const blobFile = new Blob([arrayBuffer], { type: "application/json" });
35 console.log(data);
36
37 const response = await fetch("https://api.pinata.cloud/pinning/pinFileToIPFS", {
38 method: "POST",
39 headers: {
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export default async function(request: Request): Promise<Response> {
4 const cheerio = await import("https://esm.sh/cheerio@1.0.0-rc.12");
5 const response = await fetch("https://releases.1password.com/linux/beta/");
6 const body = await response.text();
7 const $ = cheerio.load(body);
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export default async function(request: Request): Promise<Response> {
6
7 const cheerio = await import("https://esm.sh/cheerio@1.0.0-rc.12");
8 const response = await fetch(
9 "https://launchpad.net/~git-core/+archive/ubuntu/ppa/+packages",
10 );
3) {
4 if (!dmId) {
5 console.log("Fetching dmId...", { userId });
6 const channelResponse = await fetch("https://discord.com/api/users/@me/channels", {
7 method: "POST",
8 headers: {
23 console.log("sending", body);
24
25 const dmResponse = await fetch(`https://discord.com/api/channels/${dmId}/messages`, {
26 method: "POST",
27 headers: {
1import { API_URL } from "https://esm.town/v/std/API_URL";
2async function proxiedFetch(req: Request): Promise<Response> {
3 let query = new URLSearchParams({
4 url: req.url,
6 const headers = new Headers(req.headers);
7 headers.set("X-Valtown-Authorization", `Bearer ${Deno.env.get("valtown")}`);
8 return fetch(`${API_URL}/v1/fetch?${query}`, {
9 ...req,
10 headers,
12}
13import isNetworkError from "npm:is-network-error@1.0.1";
14export const resilientFetch: typeof fetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
15 const req = new Request(input, init);
16 try {
17 const res = await fetch(req);
18 if (res.ok) {
19 return res;
24 }
25 }
26 return await proxiedFetch(req);
27};
1# `resilientFetch`: faster @std/fetch
2Try to fetch unproxied first, and fall back to proxied fetch if that fails.
1/** @jsxImportSource https://esm.sh/react */
2import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=46";
3import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
4import tailwindURL from "https://esm.town/v/stevekrouse/tailwindURL";
5import { renderToString } from "npm:react-dom/server";
6
7export const reactExample = modifyFetchHandler(async (request: Request) => {
8 const url = new URL(request.url);
9 if (url.pathname === "/favicon.ico") return new Response(null, { status: 404 });
1This is an example call of @stevekrouse/insecureFetch
2
3Migrated from folder: Archive/insecureSSLCertExample