10}
1112export async function fetchEnv() {
13const { data: res, error } = await fetchValTown("/v1/eval", {
14method: "POST",
15body: JSON.stringify({
28}
2930export async function fetchValTown<T = any>(
31path: string,
32options?: RequestInit & {
4546while (true) {
47const resp = await fetch(url, {
48headers,
49});
68}
6970const resp = await fetch(`${apiURL}${path}`, {
71...options,
72headers,
96: {};
9798const { data: me } = await fetchValTown("/v1/me");
99const valDir = path.join(Deno.cwd(), me.username);
100if (!existsSync(valDir)) {
112confirm(`A new val ${file} was found. Do you want to create it on remote?`)
113) {
114const { data } = await fetchValTown("/v1/vals", {
115method: "POST",
116headers: {
139140if (confirm(`File ${file} has changed. Do you want to update it on remote?`)) {
141await fetchValTown(`/v1/vals/${meta.id}`, {
142method: "PATCH",
143headers: {
160confirm(`File ${name} was deleted. Do you want to delete it on remote?`)
161) {
162await fetchValTown(`/v1/vals/${meta.id}`, { method: "DELETE" });
163delete lock[name];
164}
170171// remote -> local
172const { data: vals } = await fetchValTown(`/v1/users/${me.id}/vals`, {
173paginate: true,
174});
246}
247248const remoteEnv = await fetchEnv();
249const localEnv = existsSync("val-town.env")
250? dotenv.parse(Deno.readTextFileSync("val-town.env"))
umbrellaRemindermain.tsx2 matches
1import { email } from "https://esm.town/v/std/email?v=9";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
3import { nominatimSearch } from "https://esm.town/v/stevekrouse/nominatimSearch";
4import { weatherGovGrid } from "https://esm.town/v/stevekrouse/weatherGovGrid";
14lon,
15});
16let { properties: { periods } } = await fetchJSON(
17grid.forecastHourly,
18);
tree_examplemain.tsx3 matches
8import { Hono } from "npm:hono";
910// The tree is fetched using an http request, so any http framework can be used
11const app = new Hono();
1249});
5051// this endpoint is used to dynamically fetch a list of tags from the api
52app.get("/tags/:tag", async (c) => {
53let { tag } = c.req.param();
85}
8687export default app.fetch;
88
jsoninvoicemain.tsx1 match
74});
7576export default app.fetch;
77
isMyWebsiteDownmain.tsx2 matches
9let reason: string;
10try {
11const res = await fetch(URL, { redirect: "follow" });
12if (res.status !== 200) {
13reason = `(status code: ${res.status})`;
15}
16} catch (e) {
17reason = `couldn't fetch: ${e}`;
18ok = false;
19}
auth_middlewaremain.tsx5 matches
35};
3637async function fetchUser(token: string): Promise<User> {
38const resp = await fetch("https://api.val.town/v1/me", {
39headers: {
40Authorization: `Bearer ${token}`,
4344if (resp.status !== 200) {
45throw new Error("Could not fetch user");
46}
475051async function isCurrentUser(userID: string) {
52const currentUser = await fetchUser(Deno.env.get("valtown"));
53return userID == currentUser.id;
54}
82const formData = await req.formData();
83const token = formData.get("token").toString();
84const user = await fetchUser(token);
85if (await isCurrentUser(user.id)) {
86return new Response("Unauthorized", {
cors_examplemain.tsx1 match
9async function request(url, options) {
10try {
11const response = await fetch(url, options);
12const status = response.status;
13const data = await response.text();