Documents generated by local access report CORS error

Does this mean that you must start a local server to access it?

The Same Origin Policy disallows reading the remote resource at file:///E:/code/me/test-zig/miniaudio.zig/zig-out/docs/main.wasm. (Reason: CORS request not http).

It seems so

Until we have a local server for our generated documentation:

python -m http.server -b 8000 -d zig-out/docs/

There is a server for the standard library:

zig std

modern java also :wink:

╰─❯ jwebserver -p 9999 -d $'(pwd)\zig-out\docs'
Binding to loopback by default. For all interfaces use "-b" or "-b ::".
Serving E:\code\me\test-zig\miniaudio.zig\zig-out\docs and subdirectories on port 9999
URL - - [11/5月/2024:14:53:32 +0800] "GET / HTTP/1.1" 200 - - - [11/5月/2024:14:53:32 +0800] "GET /main.js HTTP/1.1" 200 - - - [11/5月/2024:14:53:32 +0800] "GET /main.wasm HTTP/1.1" 200 - - - [11/5月/2024:14:53:32 +0800] "GET /sources.tar HTTP/1.1" 200 -
1 Like

We can also use redbean to build a single file document http server


    // docs
        const docs_step = b.step("docs", "Build the project documentation");
        const install_docs = b.addInstallDirectory(.{
            .source_dir = exe.getEmittedDocs(),
            .install_dir = .prefix,
            .install_subdir = "docs/",

        // (requires curl,zip)
            const docs_com_step = b.step("docscom", "Build (documentation http server powered by");

            const download_redbean = b.addSystemCommand(&.{ "curl", "-fsSLo", "", "", "--ssl-no-revoke" });
            download_redbean.has_side_effects = true;
            download_redbean.setCwd(.{ .path = b.install_path });

            const zip_docs_into_redbean = b.addSystemCommand(&.{ "zip", "-r", "", "docs" });
            zip_docs_into_redbean.has_side_effects = true;
            zip_docs_into_redbean.setCwd(.{ .path = b.install_path });

zig build docscom

and get in

β”œβ”€β”€ docs
β”‚  β”œβ”€β”€ index.html
β”‚  β”œβ”€β”€ main.js
β”‚  β”œβ”€β”€ main.wasm
β”‚  └── sources.tar

and start it

./zig-out/ -v -p 8888

╰─❯ ./zig-out/ -v -p 8888
I2024-05-12T10:33:47.859546:tool/net/redbean.c:7057:docs:19228] (srvr) listen
I2024-05-12T10:33:47+000000:tool/net/redbean.c:7057:docs:19228] (srvr) listen
I2024-05-12T10:33:47+000000:tool/net/redbean.c:7057:docs:19228] (srvr) listen
I2024-05-12T10:33:47+000000:tool/net/redbean.c:7057:docs:19228] (srvr) listen
V2024-05-12T10:33:47+000000:tool/net/redbean.c:2003:docs:19228] (ssl) could not find non-CA SSL certificate key pair with -addext keyUsage=digitalSignature -addext extendedKeyUsage=serverAuth
V2024-05-12T10:33:47+000000:tool/net/redbean.c:2006:docs:19228] (ssl) could not find CA key signing key pair with -addext keyUsage=keyCertSign
V2024-05-12T10:33:47+000000:tool/net/redbean.c:2008:docs:19228] (ssl) generating self-signed ssl certificates
V2024-05-12T10:33:47+001003:tool/net/redbean.c:680:docs:19228] (ssl) using EC certificate "CN=xxx" for HTTPS server
V2024-05-12T10:33:48.044676:tool/net/redbean.c:680:docs:19228] (ssl) using RSA certificate "CN=xxx" for HTTPS server

finally, we can open http://localhost:8888/docs/ to read docs

Well, let’s do one in Zig then: A "just-enough-functionality" Zig docs server: zds :^)