Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

Obtain the endpoint URL of the currently running val.

import { getEndpointUrl } from 'https://esm.town/v/g/getEndpointUrl'; const ENDPOINT_URL = getEndpointUrl(import.meta.url);
1
2
3
4
5
6
7
8
9
10
11
/**
* Function to extract the val HTTP endpoint URL.
* @example getEndpointUrl(import.meta.url)
* @returns endpoint url without a trailing slash
*/
export function getEndpointUrl(url: string | URL) {
const { pathname } = new URL(url);
const [author, filename] = pathname.split('/').slice(-2);
const [name] = filename.split('.');
return `https://${author}-${name}.web.val.run`;
}
August 18, 2024