### Install Dependencies Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/javascript/README.md Installs necessary tools and libraries for the spin-fileserver example, including Spin, cargo-component, wac-cli, and componentize-js. This setup ensures the environment is ready for building and running the componentized application. ```shell rustup target add wasm32-wasip1 cargo install cargo-component cargo install wac-cli npm install -g @bytecodealliance/jco @bytecodealliance/componentize-js ``` -------------------------------- ### Build Example Application Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/javascript/README.md Builds the spin-fileserver example application using the 'spin build' command. This command compiles the application and its components, preparing it for execution. ```shell spin build -u ``` -------------------------------- ### Install Spin CLI Tools Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/rust/README.md Installs necessary tools for building and running Spin applications. This includes adding the wasm32-wasip1 Rust target, the cargo-component build tool, and the wac-cli for WebAssembly component interaction. ```shell rustup target add wasm32-wasip1 cargo install cargo-component cargo install wac-cli ``` -------------------------------- ### Spin Component Configuration Example Source: https://github.com/spinframework/spin-fileserver/blob/main/README.md Example configuration for the spin-fileserver component within a Spin application's spin.toml file. It defines the HTTP route, the component source, and file mounting. ```toml [[trigger.http]] route = "/..." component = "fs" [component.fs] source = "target/wasm32-wasip1/release/spin_static_fs.wasm" files = [{ source = "", destination = "/" }] [component.fs.build] command = "make" ``` -------------------------------- ### Install Spin Framework Dependencies (Shell) Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/python/README.md Installs essential development tools and libraries for the Spin framework. This includes the WASM target, cargo-component, wac-cli, and the Python componentize-py library, preparing the environment for Spin development. ```shell rustup target add wasm32-wasip1 cargo install cargo-component cargo install wac-cli pip install componentize-py=0.13.5 ``` -------------------------------- ### Build spin-fileserver Example Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/rust/README.md Builds the Spin application. The `-u` flag ensures that all dependencies, including the spin-fileserver component, are fetched and built correctly for the project. ```shell spin build -u ``` -------------------------------- ### Run Spin Fileserver Source: https://github.com/spinframework/spin-fileserver/blob/main/README.md Starts the Spin application with the static file server component, listening on a specified address and using a configuration file. ```shell spin up --listen 127.0.0.1:3000 --file spin.toml ``` -------------------------------- ### Test spin-fileserver Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/javascript/README.md Tests the running spin-fileserver example application using curl to fetch different URIs. It demonstrates serving a dynamic response, a static text file, and handling requests for non-existent files. ```shell curl -i http://127.0.0.1:3000/hello ``` ```shell curl -i http://127.0.0.1:3000/foo.txt ``` ```shell curl -i http://127.0.0.1:3000/nonexistent.txt ``` -------------------------------- ### Test File Serving with Curl Source: https://github.com/spinframework/spin-fileserver/blob/main/README.md Example of using curl to request a file served by the Spin static file server. ```shell curl localhost:3000/LICENSE ``` -------------------------------- ### Test Fileserver Endpoint Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/rust-standalone/README.md Tests the '/hello' endpoint of the running Spin fileserver application using curl. It expects a 'Hello, world!' response, indicating the application is serving content. ```shell curl -i http://127.0.0.1:3000/hello ``` -------------------------------- ### Add WASM Target Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/rust-standalone/README.md Adds the wasm32-wasip1 target for Rust compilation, which is necessary for building WebAssembly modules compatible with Spin. ```shell rustup target add wasm32-wasip1 ``` -------------------------------- ### Build and Run Spin Application Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/rust-standalone/README.md Builds the Spin application using the 'spin build' command with the '-u' flag for updating dependencies. This command compiles the Rust code into a WebAssembly module and prepares the application for execution. ```shell spin build -u ``` -------------------------------- ### Test spin-fileserver Example with curl Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/rust/README.md Tests the running Spin application by making HTTP requests. It demonstrates accessing a custom route ('/hello') served by the app itself and static files served by spin-fileserver, as well as a non-existent file. ```shell curl -i http://127.0.0.1:3000/hello curl -i http://127.0.0.1:3000/foo.txt curl -i http://127.0.0.1:3000/nonexistent.txt ``` -------------------------------- ### Test Nonexistent File Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/rust-standalone/README.md Attempts to access a non-existent file ('nonexistent.txt') via the Spin fileserver. This tests how the component handles requests for files that are not present. ```shell curl -i http://127.0.0.1:3000/nonexistent.txt ``` -------------------------------- ### Access Static File Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/rust-standalone/README.md Accesses a static file ('foo.txt') served by the Spin fileserver using curl. This demonstrates the component's ability to serve files from the application's directory. ```shell curl -i http://127.0.0.1:3000/foo.txt ``` -------------------------------- ### Build Spin Application (Shell) Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/python/README.md Compiles the Spin application using the `spin build -u` command. This process builds the project and its components, making it ready for deployment or execution. ```shell spin build -u ``` -------------------------------- ### Create New Spin App with Fileserver Source: https://github.com/spinframework/spin-fileserver/blob/main/README.md Generates a new Spin application using the static-fileserver template. ```shell spin new -t static-fileserver ``` -------------------------------- ### Test Spin Application with Curl (Shell) Source: https://github.com/spinframework/spin-fileserver/blob/main/examples/python/README.md Tests the deployed Spin application by sending HTTP requests via `curl`. It checks responses for the `/hello` endpoint and static files served by `spin-fileserver`, including handling non-existent files. ```shell curl -i http://127.0.0.1:3000/hello ``` ```shell curl -i http://127.0.0.1:3000/foo.txt ``` ```shell curl -i http://127.0.0.1:3000/nonexistent.txt ``` -------------------------------- ### Spin Fileserver Configuration Options Source: https://github.com/spinframework/spin-fileserver/blob/main/README.md Details the environment variables used to configure the Spin static file server, including cache headers and fallback paths. ```APIDOC SpinFileserverConfiguration: Environment Variables: - CACHE_CONTROL: Sets the Cache-Control header for all served media types. If not set, defaults to `max-age=60`. - FALLBACK_PATH: Specifies a file path to return instead of a 404 Not Found response. Useful for Single Page Applications (SPAs) with client-side routing. ``` -------------------------------- ### Test Spin Fileserver Component Source: https://github.com/spinframework/spin-fileserver/blob/main/README.md Runs the test cases for the Spin static file server component. Requires Rust 1.72+ and the wasm32-wasip1 target. ```shell make test ``` -------------------------------- ### Build Spin Fileserver Component Source: https://github.com/spinframework/spin-fileserver/blob/main/README.md Compiles the Spin static file server component using cargo-component. Requires Rust 1.72+ and the wasm32-wasip1 target. ```shell cargo component build --release ``` -------------------------------- ### Add Fileserver Component to Existing App Source: https://github.com/spinframework/spin-fileserver/blob/main/README.md Adds the static-fileserver component to an existing Spin application. ```shell spin add -t static-fileserver ``` -------------------------------- ### Configure Spin Fileserver with Custom 404 Page Source: https://github.com/spinframework/spin-fileserver/blob/main/README.md This TOML configuration shows how to set a custom 404 Not Found document for the spin-fileserver. It points the CUSTOM_404_PATH environment variable to a specific HTML file within the served directory. ```toml # For more on configuring a component, see: https://developer.fermyon.com/spin/writing-apps#adding-environment-variables-to-components [component.fs] source = "target/wasm32-wasip1/release/spin_static_fs.wasm" files = [{ source = "test", destination = "/" }] environment = { CUSTOM_404_PATH = "404.html" } ``` -------------------------------- ### Configure Spin Fileserver with Fallback Path Source: https://github.com/spinframework/spin-fileserver/blob/main/README.md This TOML snippet demonstrates how to configure the spin-fileserver component to use a specific file as a fallback path. It specifies the WASM source and maps local files to the destination root, setting the FALLBACK_PATH environment variable. ```toml # For more on configuring a component, see: https://developer.fermyon.com/spin/writing-apps#adding-environment-variables-to-components [component.fs] source = "target/wasm32-wasip1/release/spin_static_fs.wasm" files = [{ source = "test", destination = "/" }] environment = { FALLBACK_PATH = "index.html" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.