Skip to content

Runtime APIs

To provide you with the best experience possible, we strive to adhere to the WinterTC requirements.

To serve a dynamic request, you either need to export a function of your choice or listen to fetch events.

export function handler(event: Request) {
return new Response('Hallo Welt!');
}
addEventListener('fetch', (event) => {
event.respondWith(new Response('Hello World!'));
});

Next to the standard built-in objects, we implement the following Browser and Node.js APIs.

  • console.log
  • console.trace
  • console.info
  • console.debug
  • console.error
  • console.warn

Please see the SubtleCrypto interface.

Similar to Vercel, we expose the EdgeRuntime property. You can use it to check if your code is running on an Edge runtime.

import { connect } from 'zugriff:sockets';
// Find more examples at https://github.com/zugriffcloud/examples/tree/main/apps
/**
* @param {Request} request
*/
export async function handler(request) {
const gopherAddr = { hostname: 'gopher.floodgap.com', port: 70 };
const url = new URL(request.url);
try {
const socket = connect(gopherAddr);
const writer = socket.writable.getWriter();
const encoder = new TextEncoder();
const encoded = encoder.encode(url.pathname + '\r\n');
await writer.write(encoded);
await writer.close();
return new Response(socket.readable, {
headers: { 'Content-Type': 'text/plain' },
});
} catch (error) {
return new Response('Socket connection failed: ' + error, { status: 500 });
}
}

Create a socket calling connect.

  • connect(address: SocketAddress | string, options?: optional SocketOptions): Socket
  • SocketAddress
    • hostname: string
    • port: number
  • SocketOptions
    • secureTransport: off | on | starttls (Defaults to off)
    • allowHalfOpen: boolean (The writable half will not automatically close) (Defaults to false)
    • insecureEncryption: boolean (Defaults to false)
      • This option is unique to zugriff and not supported by Cloudflare. We are looking into providing an option to validate self-signed certificates. (Yet, any encryption is better than no encryption.)

When connecting, a Socket is returned.

  • Socket
    • readable: ReadableStream (Returns ArrayBuffer)
    • writable: WritableStream (Processes chunks of Uint8Array or its views)
    • opened: Promise<SocketInfo> (Resolves after a connection is established)
    • closed: Promise<void> (Resolves after a connection is closed or an error occurred)
    • close(): Promise<void>
    • startTls(): Socket (After closing both the readable and writable streams, the connection is upgraded when secureTransport is set to starttls)
       
  • SocketInfo
    • remoteAddress: string | null (zugriff does not yet return a value other than null)
    • localAddress: string | null (zugriff does not yet return a value other than null)

Find information on cloudflare:sockets at https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets/.

signverifyencryptdecryptdigestderiveBitsderiveKeywrapKeyunwrapKey
RSASSA-PKCS1-v1_5
RSA-PSS
ECDSA
HMAC
RSA-OAEP
AES-CTR
AES-CBC
AES-GCM
SHA-1
SHA-256
SHA-384
SHA-512
ECDH
HKDF
PBKDF2
AES-KW
X25519
Ed25519

Please find more information at https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto#supported_algorithms.

Available Node.js modules can be imported using the ESM-import syntax.