### Initialize Bare-Mux Connection (Bundled) Source: https://github.com/titaniumnetwork-dev/ultraviolet/wiki/Upgrading Shows how to establish a connection with bare-mux using the BareMuxConnection class when a bundler is in use. This requires the path to the worker script. ```javascript import { BareMuxConnection } from "@mercuryworkshop/bare-mux" let connection = new BareMuxConnection("/baremux/worker.js") ``` -------------------------------- ### Set Ultraviolet Transport Source: https://github.com/titaniumnetwork-dev/ultraviolet/wiki/Upgrading Provides examples of how to set the transport for an established bare-mux connection. It shows setting transports like EpoxyTransport and others, including required arguments like Wisp endpoints or base URLs. ```javascript await connection.setTransport("/epoxy/index.mjs", [{ wisp: "wss://wisp.mercurywork.shop/" }]); await connection.setTransport("/baremod/index.mjs", ["https://tomp.app/"]); ``` -------------------------------- ### Host Ultraviolet Files with Express Source: https://github.com/titaniumnetwork-dev/ultraviolet/wiki/Upgrading Demonstrates how to use Express to serve static files for EpoxyTransport and bare-mux. It imports the necessary paths and uses express.static to define the routes. ```javascript import { epoxyPath } from "@mercuryworkshop/epoxy-transport"; import { baremuxPath } from "@mercuryworkshop/bare-mux/node"; app.use("/epoxy/", express.static(epoxyPath)); app.use("/baremux/", express.static(baremuxPath)); ``` -------------------------------- ### Initialize Bare-Mux Connection (No Bundler) Source: https://github.com/titaniumnetwork-dev/ultraviolet/wiki/Upgrading Illustrates how to initialize a bare-mux connection without a bundler, using the BareMux.BareMuxConnection constructor with the worker script path. ```javascript let connection = new BareMux.BareMuxConnection("/baremux/worker.js") ``` -------------------------------- ### Express Server Setup with Ultraviolet and Wisp Source: https://github.com/titaniumnetwork-dev/ultraviolet/wiki/Installing Demonstrates setting up an Express.js server to serve static assets from Ultraviolet, Epoxy, and Baremux, and handles Wisp protocol upgrades. It configures security headers and graceful shutdown. The server listens on port 8080 by default or a custom port defined by the PORT environment variable. ```javascript import express from "express"; import { createServer } from "node:http"; import { publicPath } from "ultraviolet-static"; import { uvPath } from "@titaniumnetwork-dev/ultraviolet"; import { epoxyPath } from "@mercuryworkshop/epoxy-transport"; import { baremuxPath } from "@mercuryworkshop/bare-mux/node"; import { join } from "node:path"; import { hostname } from "node:os"; import wisp from "wisp-server-node" const app = express(); // Load our publicPath first and prioritize it over UV. app.use(express.static(publicPath)); // Load vendor files last. // The vendor's uv.config.js won't conflict with our uv.config.js inside the publicPath directory. app.use("/uv/", express.static(uvPath)); app.use("/epoxy/", express.static(epoxyPath)); app.use("/baremux/", express.static(baremuxPath)); // Error for everything else app.use((req, res) => { res.status(404); res.sendFile(join(publicPath, "404.html")); }); const server = createServer(); server.on("request", (req, res) => { res.setHeader("Cross-Origin-Opener-Policy", "same-origin"); res.setHeader("Cross-Origin-Embedder-Policy", "require-corp"); app(req, res); }); server.on("upgrade", (req, socket, head) => { if (req.url.endsWith("/wisp/")) wisp.routeRequest(req, socket, head); else socket.end(); }); let port = parseInt(process.env.PORT || ""); if (isNaN(port)) port = 8080; server.on("listening", () => { const address = server.address(); // by default we are listening on 0.0.0.0 (every interface) // we just need to list a few console.log("Listening on:"); console.log(` http://localhost:${address.port}`); console.log(` http://${hostname()}:${address.port}`); console.log( ` http://${address.family === "IPv6" ? `[${address.address}]` : address.address }:${address.port}` ); }); // https://expressjs.com/en/advanced/healthcheck-graceful-shutdown.html process.on("SIGINT", shutdown); process.on("SIGTERM", shutdown); function shutdown() { console.log("SIGTERM signal received: closing HTTP server"); server.close(); process.exit(0); } server.listen({ port, }); ``` -------------------------------- ### Install Ultraviolet with npm Source: https://github.com/titaniumnetwork-dev/ultraviolet/wiki/Installing Installs the @titaniumnetwork-dev/ultraviolet package using npm, making its built files and JS API available for use in your project. ```sh npm install @titainiumnetwork-dev/ultraviolet ``` -------------------------------- ### Install Older Ultraviolet Version (npm) Source: https://github.com/titaniumnetwork-dev/ultraviolet/blob/main/README.md Installs an older, unsupported version of Ultraviolet (v1) using npm. This is an alternative if you cannot upgrade to the latest version. ```sh npm install @titaniumnetwork-dev/ultraviolet@1 ``` -------------------------------- ### Setting Ultraviolet Configuration Source: https://github.com/titaniumnetwork-dev/ultraviolet/wiki/Configuration This snippet demonstrates how to set the `__uv$config` property on the `self` object in a JavaScript environment. This configuration object allows customization of Ultraviolet's behavior, including URL prefix, encoding/decoding functions, and paths to various scripts like the handler, client, bundle, config, and service worker. ```javascript self.__uv$config = { prefix: "/uv/", encodeUrl: (str) => str, decodeUrl: (str) => str, handler: "/uv/uv.handler.js", client: "/uv/uv.client.js", bundle: "/uv/uv.bundle.js", config: "/uv/uv.config.js", sw: "/uv/uv.sw.js" }; ``` -------------------------------- ### Ultraviolet Script Directory Structure Source: https://github.com/titaniumnetwork-dev/ultraviolet/wiki/Prebuilt-Scripts This snippet illustrates the typical file structure found within the 'dist' directory of the Ultraviolet NPM package. It includes essential JavaScript files for the service worker, client, configuration, and handlers. ```text .\n└── package\n ├── dist\n │   ├── sw.js\n │   ├── uv.bundle.js\n │   ├── uv.client.js\n │   ├── uv.config.js\n │   ├── uv.handler.js\n │   ├── uv.sw.js ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.