Search
vtTokenSessionAuth
@stevekrouse
Val Town Token Session Auth Protect your vals behind your Val Town API Token. Use session cookies to persist authentication. Forked from @pomdtr/password_auth. Usage import { vtTokenSessionAuth } from "https://esm.town/v/stevekrouse/vtTokenSessionAuthSafe";
export default vtTokenSessionAuth(() => Response.json("Authenticated!")) To sign out, navigate to /signout .
Script
# Val Town Token Session Auth
Protect your vals behind your Val Town API Token. Use session cookies to persist authentication.
Forked from @pomdtr/password_auth.
## Usage
```ts
export default vtTokenSessionAuth(() => Response.json("Authenticated!"))
type Session = {
id: string;
expiresAt: number;
async function createSessionTable(tableName: string) {
aqi
@lavallee
An interactive, runnable TypeScript val by lavallee
Cron
export let aqi = async () => {
let pm25 = (
await fetchJSON(
"https://api.openaq.org/v2/latest?" +
new URLSearchParams({
limit: "10",
page: "1",
location: "Miami",
offset: "0",
sort: "desc",
printHeaders
@andreterron
An interactive, runnable TypeScript val by andreterron
Script
export const printHeaders = async (req: express.Request, res) => {
console.log("HEADERS");
console.log(req.options.headers);
res.send(req.options.headers);
consoleEmailEx
@adam12
An interactive, runnable TypeScript val by adam12
Script
export let consoleEmailEx = () => {
console.email(`message the current time is ${new Date()}`); // any JSON object can be the message
console.email({ html: "<h1>hello html emails!</h1>" }); // you can send HTML emails
console.email({ hi: "there" }, "Subject Line"); // optional second arg is the subject line
console.email({ html: "<b>hi!</b>", subject: "Subject accepted here too" });
signedFetch
@vladimyr
// SPDX-License-Identifier: 0BSD
Script
// SPDX-License-Identifier: 0BSD
export type SignatureOptions = {
pkcs8: string;
publicKeyId: string | URL;
algorithm?: "rsa-sha256";
signFn?: (message: string, pkcs8: string, algorithm: SignatureOptions["algorithm"]) => Promise<string>;
export function createSignedFetch(
options: SignatureOptions & {
fetch?: typeof fetch;
const fetch = options.fetch ?? globalThis.fetch;
activitypub
@tmcw
WebFinger This is a not-quite-complete ActivityPub implementation based on my blog post about building an AP implementation . It includes enough to look up bot@tmcw-activitypub.web.val.run on Mastodon and get some basic information.
HTTP
# WebFinger
This is a not-quite-complete ActivityPub implementation based on my [blog post about building an AP implementation](https://macwright.com/2022/12/09/activitypub). It includes enough to look up `bot@tmcw-activitypub.web.val.run` on Mastodon and get some basic information.
export const activitypub = async (req: Request) => {
const { Hono } = await import("npm:hono@3.4.3");
const app = new Hono();
const DOMAIN = "tmcw-activitypub.web.val.run";
const USERS = new Map([
`acct:bot@${DOMAIN}`,
subject: `acct:bot@${DOMAIN}`,
aliases: [],
resumeWebsite
@ajax
An interactive, runnable TypeScript val by ajax
Script
import { resumeHtml } from "https://esm.town/v/ajax/resumeHtml";
export function resumeWebsite(req, res) {
res.set("Content-Type", "text/html");
res.send(resumeHtml);
getValTownTest
@xiyouMc
An interactive, runnable TypeScript val by xiyouMc
Script
import { getValTown } from "https://esm.town/v/xiyouMc/getValTown";
export let getValTownTest = (async () => {
return await getValTown();
northernChocolateFish
@seanyang0813
An interactive, runnable TypeScript val by seanyang0813
Cron
import { email } from "https://esm.town/v/std/email";
export default async function(interval: Interval) {
await email({
subject: "This is your daily ping!",
text: "Do your daily ping at https://benjaminaster.com/daily-ping/",
turquoiseLlama
@rvorias
An interactive, runnable TypeScript val by rvorias
HTTP
const gist =
"https://gist.githubusercontent.com/rvorias/2af68a5974bdbebba5925bbdba52c07d/raw/4320ade50bcccd020127db24607ca4fac71ff0f6/data.json";
export const queryParams = async (req: Request) => {
const data = await fetch(gist);
const jsonData = await data.json();
const searchParams = new URL(req.url).searchParams;
const params = Object.fromEntries(searchParams.entries());
const id = parseInt(params["id"]) - 1;
const code = jsonData["data"][id];
let ans;
feps
@vladimyr
An interactive, runnable TypeScript val by vladimyr
HTTP
import { Hono } from "npm:hono@3.12.7";
const app = new Hono();
app.get("/:fepId{[A-za-z0-9]{4}}", (c) => {
const fepId = c.req.param("fepId").toLowerCase();
return c.redirect(`https://codeberg.org/fediverse/fep/src/branch/main/fep/${fepId}/fep-${fepId}.md`);
export default app.fetch;
greetWebhook
@tmalaher
An interactive, runnable TypeScript val by tmalaher
Script
export let greetWebhook = (req: express.Request, res: express.Response) => {
res.json({ data: `Hello, ${req.body.name}!` });
// res.status(500).send("Testing");
getPocket
@jessmartin
An interactive, runnable TypeScript val by jessmartin
Script
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export function getPocket(params) {
return fetchJSON("https://getpocket.com/v3/get", {
method: "POST",
body: JSON.stringify(params),
primewire
@temptemp
An interactive, runnable TypeScript val by temptemp
Script
const NotFoundError = Error;
primewireApiKey,
primewireBase,
} from "https://raw.githubusercontent.com/Ciarands/mw-providers/dev/src/providers/sources/primewire/common.ts";
async function search(imdbId: string) {
const searchResult = await fetch(`${primewireBase}/api/v1/show?key=${primewireApiKey}&imdb_id=${imdbId}`);
return await searchResult.json().then((searchResult) => {
return searchResult.id;
async function getStreams(title: string) {
const titlePage = load(title);
proxyFetch1
@alp
An interactive, runnable TypeScript val by alp
Script
import { fetch } from "https://esm.town/v/std/fetch";
export const proxyFetch1 = async (req, res) => {
const { url, options } = req.body;
try {
const response = await fetch(url, options);
return res.status(response.status).send(await response.text());
} catch (e) {
const errorMessage = e instanceof Error ? e.message : "Unknown error";
console.error("Failed to initiate fetch", e);
return res.status(500).send(`Failed to initiate fetch: ${errorMessage}`);