Menu

Installing

poop fart

How do I install this?

This will provide built files and the JS API to access the path of dist files.

npm install @titainiumnetwork-dev/ultraviolet

You can use this in your project via:

import { createServer } from "node:http";
import createBareServer from "@tomphttp/bare-server-node";
import { uvPath } from "@titaniumnetwork-dev/ultraviolet";

const bare = createBareServer("/bare/");
const app = express();

app.use(express.static(publicPath));
app.use("/uv/", express.static(uvPath));

const server = createServer();

server.on("request", (req, res) => {
  if (bare.shouldRoute(req)) {
    bare.routeRequest(req, res);
  } else {
    app(req, res);
  }
});

server.on("upgrade", (req, socket, head) => {
  if (bare.shouldRoute(req)) {
    bare.routeUpgrade(req, socket, head);
  } else {
    socket.end();
  }
});

server.listen({
  port: 8080,
});

This code sets up an Express web server that serves static files from a publicPath directory and the uvPath directory, which contains the Ultraviolet library. It also sets up a TompHTTP Bare server at the /bare/ URL prefix and routes requests to the appropriate server based on the request URL.

The Express server is created using the express module, and it serves static files using the express.static middleware. The Bare server is created using the createBareServer function imported from the @tomphttp/bare-server-node package, and it is used to handle requests to URLs that start with /bare/.

The code then sets up an HTTP server using the createServer function from the node:http module, and it listens for requests and upgrades on that server. When a request or upgrade is received, the code checks whether it should be handled by the Bare server or the Express server, and it routes the request to the appropriate server. Finally, the server is started on port 8080.