Early Return497 words
Section titled “How to return early, and process after” early-returning.tsRun in Val Town ↗ async function handle(req: Request) { const new = new URL(req.url). if (url.path === '/') { //
Sections
How to return early, and process after
How to return early, and process after. Section titled “How to return early, and process after” early-returning.tsRun in Val Town ↗ async function handle(req: Request) { const new = new
Promises should otherwise be awaited
to use await with Promises, errors that occur in promises won’t be properly handled and functions may run out-of-order. For example, if you use fetch to request some resource, but
Deno LSP1413 words
currently loading your Val and downloading its dependencies. The LSP will be functional in this state but its functionality will be degraded — you may see “unresolved import” errors, for
Sections
Deno LSP
currently loading your Val and downloading its dependencies. The LSP will be functional in this state but its functionality will be degraded — you may see “unresolved import” errors, for
Features
a symbol). Signature reference (a box indicating the arguments a function takes that shows up when you are typing a function invocation). Deno supports a top level deno.json file to
Multi Tab Editing
to the return type of a function in one tab, and you have a file open in another tab that imports and uses that function, that tab may see red
Receiving a GitHub Webhook369 words
of your webhook. Securing GitHub Webhooks. Section titled “Securing GitHub Webhooks” Once public, your val function will listen for any payload sent to its endpoint. For security reasons, you probably
Sections
Securing GitHub Webhooks
GitHub Webhooks” Once public, your val function will listen for any payload sent to its endpoint. For security reasons, you probably want to limit requests to those coming from GitHub.
Send Discord message via webhook129 words
body: JSON.stringify({ content }), }); if (text.length) throw Error("Discord Webhook error: " + text); }; You can browse example usages of this function here. Example Integration. Section titled “Example Integration”
Sections
Send Discord message via webhook
throw Error("Discord Webhook error: " + text); }; You can browse example usages of this function here.
RSS153 words
"https://esm.town/v/std/email?v=9"; import { newRSSItems } from "https://esm.town/v/stevekrouse/newRSSItems"; import { rssFeeds } from "https://esm.town/v/stevekrouse/rssFeeds"; export async function pollRSSFeeds({ lastRunAt }: Interval) { return Promise.all( Object.entries(rssFeeds).map(async ([name, url]) => { let items
Sections
Polling RSS
"https://esm.town/v/std/email?v=9"; import { newRSSItems } from "https://esm.town/v/stevekrouse/newRSSItems"; import { rssFeeds } from "https://esm.town/v/stevekrouse/rssFeeds"; export async function pollRSSFeeds({ lastRunAt }: Interval) { return Promise.all( Object.entries(rssFeeds).map(async ([name, url]) => { let items
ORMs206 words
Prisma. Section titled “Prisma” 🚫 Prisma isn’t supported in Val Town because it relies on functionality that only exists in a classic server environment. Sequelize. Section titled “Sequelize” 🚫 Sequelize
Sections
Prisma
Prisma. Section titled “Prisma” 🚫 Prisma isn’t supported in Val Town because it relies on functionality that only exists in a classic server environment.
Importing674 words
mind, and won’t work with Deno. While Deno implements most of the functionality of Node.js and some of the functionality of browsers - so many modules will “just work” in
Sections
Look for Deno compatibility
mind, and won’t work with Deno. While Deno implements most of the functionality of Node.js and some of the functionality of browsers - so many modules will “just work” in
Stripe741 words
@ts-ignore. import { Stripe } from "npm:stripe"; const stripe = new Stripe(Deno.env.get("STRIPE_TEST_API_KEY")); export default async function (req: Request): Promise<Response> { const url = new URL(req.url); if (url.pathname === "/") {
Sections
Stripe Checkout
@ts-ignore. import { Stripe } from "npm:stripe"; const stripe = new Stripe(Deno.env.get("STRIPE_TEST_API_KEY")); export default async function (req: Request): Promise<Response> { const url = new URL(req.url); if (url.pathname === "/") {
Example Val Town Stripe Webhook
from "npm:stripe"; const stripe = new Stripe( Deno.env.get("stripe_sk_customer_readonly") as string, { apiVersion: "2020-08-27", } ); function getStripeCustomer(customerId: string) { return stripe.customers.retrieve(customerId); } export let newStripeEvent = async (req: Request) =>
Permission errors345 words
to your secrets (--allow-env). Some system information (--allow-sys=osRelease,homedir,cpus,hostname) This allows you to access the following functionality: import os from "node:os"; os.cpus(); os.homedir(); Deno.osRelease(); Deno.hostname(); These values are not particularly useful,
Sections
Allowed permissions
to your secrets (--allow-env). Some system information (--allow-sys=osRelease,homedir,cpus,hostname) This allows you to access the following functionality: import os from "node:os"; os.cpus(); os.homedir(); Deno.osRelease(); Deno.hostname(); These values are not particularly useful,
Upgrade Guide: Safer Val Scopes378 words
is deprecated and we now use blob storage with our std/blob library instead. The equivalent function to std.set() is blob.setJSON(). // Using std/set. import { set } from "https://esm.town/v/std/set"; set("createdAt",
Sections
Use Blob Storage Instead (recommended)
Use Blob Storage Instead (recommended). Section titled “Use Blob Storage Instead (recommended)” Std/set is deprecated and we now use blob storage with our std/blob library instead. The equivalent function to