Skip to content

Commit 263eaa6

Browse files
committed
fix yet another bug
1 parent a3eb685 commit 263eaa6

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

server.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { baremuxPath } from '@mercuryworkshop/bare-mux/node';
77
import { join } from 'node:path';
88
import { hostname } from 'node:os';
99
import wisp from 'wisp-server-node';
10+
import Ultraviolet from '@titaniumnetwork-dev/ultraviolet';
11+
import uvConfig from './uv.config.js';
1012

1113
const app = express();
1214

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

29+
// Configure Ultraviolet
30+
const uv = new Ultraviolet(uvConfig);
31+
32+
// Generate proxied URL
33+
app.get('/generate-proxy-url', (req, res) => {
34+
const serviceUrl = req.query.url;
35+
if (serviceUrl) {
36+
const encodedUrl = uv.encodeUrl(serviceUrl);
37+
const proxyUrl = `http://${hostname()}:${port}/service/${encodedUrl}`;
38+
res.send(proxyUrl);
39+
} else {
40+
res.status(400).send('No URL provided');
41+
}
42+
});
43+
44+
// Use Ultraviolet middleware
45+
app.use('/service/', uv.middleware());
46+
2747
// Error for everything else
2848
app.use((req, res) => {
2949
res.status(404);

uv.config.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import Ultraviolet from '@titaniumnetwork-dev/ultraviolet';
2+
13
const uvConfig = {
24
prefix: '/service/',
35
bare: '/bare/',
46
encodeUrl: Ultraviolet.codec.xor.encode,
57
decodeUrl: Ultraviolet.codec.xor.decode,
6-
handler: '/dist/uv.handler.js',
7-
bundle: '/dist/uv.bundle.js',
8-
config: '/dist/uv.config.js',
9-
sw: '/dist/uv.sw.js',
8+
handler: '/uv/uv.handler.js',
9+
bundle: '/uv/uv.bundle.js',
10+
config: '/uv/uv.config.js',
11+
sw: '/uv/uv.sw.js',
1012
};
1113

1214
export default uvConfig;

0 commit comments

Comments
 (0)