Runtime APIs
To provide you with the best experience possible, we strive to adhere to the WinterTC requirements.
Request Handler
Section titled “Request Handler”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!'));});Global Objects
Section titled “Global Objects”Next to the standard built-in objects, we implement the following Browser and Node.js APIs.
console.logconsole.traceconsole.infoconsole.debugconsole.errorconsole.warn
Please see the SubtleCrypto interface.
Date (built-in)
Section titled “Date (built-in)”EdgeRuntime
Section titled “EdgeRuntime”Similar to Vercel, we expose the EdgeRuntime property. You can use it to check if your code is running on an Edge runtime.
Sockets (TCP)
Section titled “Sockets (TCP)”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): SocketSocketAddresshostname: stringport: number
SocketOptionssecureTransport: off | on | starttls(Defaults tooff)allowHalfOpen: boolean(The writable half will not automatically close) (Defaults tofalse)insecureEncryption: boolean(Defaults tofalse)- This option is unique to
zugriffand not supported by Cloudflare. We are looking into providing an option to validate self-signed certificates. (Yet, any encryption is better than no encryption.)
- This option is unique to
When connecting, a Socket is returned.
Socketreadable: ReadableStream(ReturnsArrayBuffer)writable: WritableStream(Processes chunks ofUint8Arrayor 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 whensecureTransportis set tostarttls)
SocketInforemoteAddress: string | null(zugriffdoes not yet return a value other thannull)localAddress: string | null(zugriffdoes not yet return a value other thannull)
Find information on cloudflare:sockets at https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets/.
| sign | verify | encrypt | decrypt | digest | deriveBits | deriveKey | wrapKey | unwrapKey | |
|---|---|---|---|---|---|---|---|---|---|
| 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.
Node.js compatibility
Section titled “Node.js compatibility”Available Node.js modules can be imported using the ESM-import syntax.