2import { forbidden } from "https://esm.town/v/emarref/HttpResponse";
3
4export function requireHttpMethod(method: Request["method"]): HttpMiddleware {
5 return function(next) {
6 return function(request) {
7 if (request.method !== method) {
8 console.warn(`${method} method required.`);
1Chainable middleware functions to simplify http requests.
2
3Migrated from folder: http/middleware/HttpMiddleware
1An implementation of chainable http middleware.
2
3Wrap your http handlers in middleware to add functionality and reduce code duplication.
4
5```ts
6export default function chain()
7 .then(add(requireHttpMethod("post")))
8 .then(add(requireAuthentication()))
1Factory functions for creating HTTP Response objects.
2
3Migrated from folder: http/HttpResponse
1if (import.meta.main) Deno.serve(translate);
2
3export async function translate(req: Request) {
4 if (req.method === "POST") {
5 return await fetch("https://deepl.deno.dev/translate", {
45 };
46
47 translate = async function () {
48 this.setState({ loading: true, translation: "" });
49 const { text, source_lang, target_lang } = this.state;
52 }.bind(this);
53
54 swap = function () {
55 if (this.state.source_lang.toLowerCase() === "auto") {
56 this.setState({ source_lang: "en" });
62 }.bind(this);
63
64 handleShortcut = function (e) {
65 if (this.state.loading !== true && e.ctrlKey && e.key === "Enter") {
66 this.translate();
125 render(html\`<\${App} page="All" />\`, document.body);
126
127 async function translate({ text, source_lang, target_lang }) {
128 const Options = z.object({
129 text: z.string(),
27 output: null,
28 init() {
29 // if you don't use an arrow function (this) will refer to document, not alpine
30 document.addEventListener('htmx:afterRequest', (event) => this.updateOutput(event));
31 },
27 output: null,
28 init() {
29 // if you don't use an arrow function (this) will refer to document, not alpine
30 document.addEventListener('htmx:afterSwap', (event) => this.updateOutput(event));
31 },
1import { OpenAI } from "https://esm.town/v/std/openai";
2export default async function(req: Request): Promise<Response> {
3 const openai = new OpenAI();
4 const stream = await openai.chat.completions.create({
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request): Promise<Response> {
5 return new Response(
6 renderToString(
11 {`let hasAnError: string = 10;
12
13function increment(num: number) {
14 return num + 1;
15}
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3export default async function(req: Request): Promise<Response> {
4 const openai = new OpenAI();
5 const stream = await openai.chat.completions.create({
A helper function to build a file's email
Simple functional CSS library for Val Town
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.