Search
valle_tmp_53076151180486396547071678302139
@janpaul123
// This val will respond with a fun and styled HTML page saying "Hello, world!"
HTTP
// This val will respond with a fun and styled HTML page saying "Hello, world!"
export default async function main(): Promise<Response> {
const htmlContent = `
<!DOCTYPE html>

private_fal_model
@turbo1912
@jsxImportSource https://esm.sh/react
Cron
import fal from "npm:@fal-ai/serverless-client";
import { renderToString } from "npm:react-dom/server";
export default async function(interval: Interval) {
const result = await fal.subscribe("turbo1912/multiple-models/esrgan", {
input: {

hnFollowPollJob
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
import { hackerNewsAuthors } from "https://esm.town/v/stevekrouse/hackerNewsAuthors";
import { hnLatestPosts } from "https://esm.town/v/stevekrouse/hnLatestPosts";
export async function hnFollowPollJob({ lastRunAt }) {
let posts = await hnLatestPosts({
authors: hackerNewsAuthors,
deployBackend
@toowired
An interactive, runnable TypeScript val by toowired
Script
export default function deployBackend({ code, schema, dependencies }) {
// Input Validation
if (!code || typeof code !== 'string') {
discordBot
@dglazkov
A simple Discord Bot scaffolding, a slight rev on the one in the valtown guide . The discordBot function takes in an object where each key is a Discord command and the value is a function to handle the command. If the function returns a Promise , it will be handled as a deferred interaction with a followup message . Usage:
import { discordBot } from "https://esm.town/v/dglazkov/discordBot";
const echo = async (data) => {
await new Promise((r) => setTimeout(r, 5000));
return {
type: 4,
data: {
content: data.data.options[0].value,
},
};
};
export default discordBot({
ping: () => ({
type: 4,
data: {
content: `Pong! It is ${new Date()}`,
},
})
echo,
});
Script
A simple Discord Bot scaffolding, a slight rev on the one in the [valtown guide](https://docs.val.town/integrations/discord/how-to-make-a-discord-bot-hosted-24-7-for-free-in-/).
The `discordBot` function takes in an object where each key is a Discord command and the value is a function to handle the command. If the function returns a `Promise`, it will be handled as a deferred interaction with a [followup message](https://discord.com/developers/docs/interactions/receiving-and-responding#followup-messages).
Usage:
websitesSeoAnalyzer
@mdalam7294
@jsxImportSource https://esm.sh/react@18.2.0
HTTP
import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
function SeoAnalyzer() {
const [url, setUrl] = useState('');
</div>
function client() {
createRoot(document.getElementById("root")).render(<SeoAnalyzer />);
if (typeof document !== "undefined") { client(); }
export default async function server(request: Request): Promise<Response> {
if (request.method === 'POST' && new URL(request.url).pathname === '/analyze') {
myApi
@red_dylan
An interactive, runnable TypeScript val by red_dylan
Script
export function myApi(name) {
return "hi " + name;

myApi
@ralphite
An interactive, runnable TypeScript val by ralphite
Script
export function myApi(name) {
return "hi " + name;
web_5If23gmesX
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function web_5If23gmesX(req) {
return new Response(`<!DOCTYPE html>
<html lang="en">
grimPinkLimpet
@jdan
// This approach will use the Notion API to update a block's color.
HTTP
// This approach will use the Notion API to update a block's color.
// We'll create a simple HTML page with a button, and use JavaScript to handle
// the click event and make a request to our Val Town function.
// The function will then make a request to the Notion API to update the block.
import { Hono } from "npm:hono";
const app = new Hono();
pageSpeedAPI
@eligosmlytics
@jsxImportSource https://esm.sh/react
HTTP
import { createRoot } from "https://esm.sh/react-dom/client";
function Popup({ isOpen, onClose, content }) {
if (!isOpen) return null;
</div>
function HTMLPreview({ html, isFullView, toggleView }) {
return (
</div>
function App() {
const [url, setUrl] = useState('');
</div>
function client() {
createRoot(document.getElementById("root")).render(<App />);
client();
export default async function server(request: Request): Promise<Response> {
const url = new URL(request.url);

auth_middleware
@stevekrouse
Authentication middleware Guards your public http vals behind a login page. This val use a json web token stored as an http-only cookie to persist authentication. Usage Set an AUTH_SECRET_KEY env variable (used to sign/verify jwt tokens). Use an API token to authenticate. import { auth } from "https://esm.town/v/pomdtr/auth_middleware";
async function handler(req: Request): Promise<Response> {
return new Response("You are authenticated!");
}
export default auth(handler); See @pomdtr/test_auth for an example ⚠️ Make sure to only provides your api token to vals you trust (i.e. your own), as it gives access to your whole account.
Script
import { auth } from "https://esm.town/v/pomdtr/auth_middleware";
async function handler(req: Request): Promise<Response> {
return new Response("You are authenticated!");
</html>`;
export function redirect(location: string): Response {
return new Response(null, {
status: 302,
function generateAccessToken(user) {
return jwt.sign(user, process.env.ACCESS_TOKEN_SECRET, { expiresIn: "1800s" });
username: string;
async function fetchUser(token: string): Promise<User> {
const resp = await fetch("https://api.val.town/v1/me", {
return resp.json();
function signout() {
const res = redirect("/");
return res;
export function auth(handler) {
const secretKey = Deno.env.get("AUTH_SECRET_KEY");

myApi
@davidar
An interactive, runnable TypeScript val by davidar
Script
export function myApi(name) {
return "hi " + name;