Versions

  • v2

    8/14/2024
    Open: Version
    Changes from v1 to v2
    +2
    -1
    const { PhpWeb } = await import("https://cdn.jsdelivr.net/npm/php-wasm/PhpWeb.mjs");

    export default async function(req: Request): Promise<Response> {
    const php = new PhpWeb();
    let output = "";
    let headers = new Headers();
    ⦚ 135 unchanged lines ⦚
    const { PhpWeb } = await import("https://cdn.jsdelivr.net/npm/php-wasm/PhpWeb.mjs");

    const php = new PhpWeb();

    export default async function(req: Request): Promise<Response> {
    let output = "";
    let headers = new Headers();
    ⦚ 135 unchanged lines ⦚
  • v1

    8/14/2024
    Open: Version
    Changes from v0 to v1
    +140
    -2
    export default async function (req: Request): Promise<Response> {
    return Response.json({ ok: true })
    }
    const { PhpWeb } = await import("https://cdn.jsdelivr.net/npm/php-wasm/PhpWeb.mjs");

    export default async function(req: Request): Promise<Response> {
    const php = new PhpWeb();
    let output = "";
    let headers = new Headers();

    php.addEventListener("output", (event: any) => {
    output += event.detail.join("");
    });

    php.addEventListener("header", (event: any) => {
    const [header, value] = event.detail.split(":");
    headers.append(header.trim(), value.trim());
    });

    const url = new URL(req.url);
    const method = req.method;

    // Escape special characters for PHP
    const escapeForPHP = (str: string) => str.replace(/['\\]/g, "\\$&");

    // Prepare request data for PHP
    const requestBody = method !== "GET" && method !== "HEAD" ? await req.text() : "";

    const requestData = {
    method: method,
    uri: url.pathname,
    queryString: url.search.slice(1),
    headers: Object.fromEntries(req.headers),
    body: requestBody,
    };

    const script = `<?php
    // Set up superglobals
    $_SERVER['REQUEST_METHOD'] = '${escapeForPHP(requestData.method)}';
  • v0

    8/14/2024
    Open: Version
    +3
    -0

    export default async function (req: Request): Promise<Response> {
    return Response.json({ ok: true })
    }
1
Next
harveyfullstack-phpserve.web.val.run
Updated: August 14, 2024