Readme

Get redirect to val Response

In cases a web endpoint val expects a certain method like POST, you can use this val to redirect the user to the page of the val using this val, so they can read the readme and use it correctly.

Preferably to use when the method is get, since it might be done by entering the web endpoint into the browser. But if you don't like to return a 405 status for unallowed methods, you can use it for anything but the expected method(s).

if (req.method === "GET") { return @karfau.getRedirectToValResponse(); }
1
2
3
4
5
6
7
8
9
10
11
import { refToValUrl } from "https://esm.town/v/karfau/refToValUrl";
import { mainReference } from "https://esm.town/v/karfau/mainReference";
export const getRedirectToValResponse = () => {
const url = mainReference(refToValUrl);
return new Response(`Redirecting to <a href="${url}">${url}</a>`, {
status: 303,
headers: { Location: url },
});
};
// Forked from @neverstew.thisValUrl
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023