/Easyviolet

An easy way to use the ultraviolet proxy.

Primary LanguageJavaScriptMIT LicenseMIT

Easyviolet

An easy way to use the proxy Ultraviolet. Easyviolet allows you to setup and configure the proxy Ultraviolet using one line of code and still have Ultraviolet's full functionality and customizability.

Installation

$ npm install github:Russell2259/Easyviolet

Demo

You can see more examples here.

import Easyviolet from 'easyviolet';
import http from 'node:http';

const server = http.createServer();

new Easyviolet({
  server: server
});

server.listen(8080, () => {
  console.log(`Your easyviolet demo is running on port ${server.address().port}`);
});

Configuration

The configuration for easyviolet

// All of these values are predefined except for the server object

new Easyviolet({
    uvPrefix: '/uv/', // The prefix that ultraviolet will run on
    prefix: 'service/', // The path that ultraviolet will serve proxied content to
    bare: '/bare/', // The path that the bare server will be run on
    codec: 'xor',
    server: server // The server object provided by the node:http module
});

Features

Useful features that are provided by easyviolet

const ultraviolet = new Easyviolet();

// Use an express.js server with easyviolet
const app = express();

ultraviolet.httpServer(app.listen(80));

// Check if easyviolet needs a path
ultraviolet.requiresRoute(req); // Requires the request object provided by the express and node:http modules

// Use a http server after easyviolet has been configured
ultraviolet.httpServer(server); // Requires the server object provided by the node:http module

// Handle a request without registering a server
ultraviolet.handleRequest(req, res, next/* Optional */);

Client Side API

Easyviolet also provides a client side javascript api for easy use and configuration.

Link the script

<script src="/{your prefix}/ev.bundle.js"></script>

<!--The default prefix is uv-->
<script src="/uv/ev.bundle.js"></script>

Use the api in your code

// Register the ultraviolet service worker (is done automatically when the script is linked)
await Easyviolet.registerSW();

// Use than and catch
Easyviolet.registerSW().then(() => console.log('yay!')).catch(e => console.log('An error occurred: ', e));

// Encode a url
Easyviolet.getProxiedUrl('https://example.com');

// Other parameters
Easyviolet.scriptsLoaded; // Returns true|false
Easyviolet.config; // The configuration passed down from the node process in json format

Credits

The two primary libraries ultraviolet and bare server node were not developed by me and easyviolet was only intended to be an easier way to use the ultraviolet proxy.

Thanks again to all of these amazing contributors for helping develop easyviolet