Skip to content

Commit

Permalink
fix yet another bug
Browse files Browse the repository at this point in the history
  • Loading branch information
browser-vm committed Feb 7, 2025
1 parent a3eb685 commit 263eaa6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
20 changes: 20 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { baremuxPath } from '@mercuryworkshop/bare-mux/node';
import { join } from 'node:path';
import { hostname } from 'node:os';
import wisp from 'wisp-server-node';
import Ultraviolet from '@titaniumnetwork-dev/ultraviolet';
import uvConfig from './uv.config.js';

const app = express();

Expand All @@ -24,6 +26,24 @@ app.use('/uv/', express.static(uvPath));
app.use('/epoxy/', express.static(epoxyPath));
app.use('/baremux/', express.static(baremuxPath));

// Configure Ultraviolet
const uv = new Ultraviolet(uvConfig);

// Generate proxied URL
app.get('/generate-proxy-url', (req, res) => {
const serviceUrl = req.query.url;
if (serviceUrl) {
const encodedUrl = uv.encodeUrl(serviceUrl);
const proxyUrl = `http://${hostname()}:${port}/service/${encodedUrl}`;
res.send(proxyUrl);
} else {
res.status(400).send('No URL provided');
}
});

// Use Ultraviolet middleware
app.use('/service/', uv.middleware());

// Error for everything else
app.use((req, res) => {
res.status(404);
Expand Down
10 changes: 6 additions & 4 deletions uv.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import Ultraviolet from '@titaniumnetwork-dev/ultraviolet';

const uvConfig = {
prefix: '/service/',
bare: '/bare/',
encodeUrl: Ultraviolet.codec.xor.encode,
decodeUrl: Ultraviolet.codec.xor.decode,
handler: '/dist/uv.handler.js',
bundle: '/dist/uv.bundle.js',
config: '/dist/uv.config.js',
sw: '/dist/uv.sw.js',
handler: '/uv/uv.handler.js',
bundle: '/uv/uv.bundle.js',
config: '/uv/uv.config.js',
sw: '/uv/uv.sw.js',
};

export default uvConfig;

0 comments on commit 263eaa6

Please sign in to comment.