Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,38 @@ app.use(express.static('public'));
app.get('/generate-proxy-url', (req, res) => {
const serviceUrl = req.query.url;
if (serviceUrl) {
const encodedUrl = Buffer.from(serviceUrl).toString('base64');
const proxyUrl = `http://${hostname()}:${port}/service/${encodedUrl}`;
res.send(proxyUrl);
try {
const encodedUrl = Buffer.from(serviceUrl, 'utf-8').toString('base64');
const proxyUrl = `http://${hostname()}:${port}/service/${encodedUrl}`;
console.log(`Generated proxy URL: ${proxyUrl}`);
res.send(proxyUrl);
} catch (error) {
console.error('Error encoding URL:', error);
res.status(500).send('Error generating proxy URL');
}
} else {
res.status(400).send('No URL provided');
}
});

// Ultraviolet handler
app.use('/service/*', (req, res) => {
const urlToProxy = Buffer.from(req.url.slice(1), 'base64').toString('utf-8');
req.url = urlToProxy;
uvPath.requireHandle()(req, res);
try {
const encodedPart = req.url.split('/service/')[1];
const urlToProxy = Buffer.from(encodedPart, 'base64').toString('utf-8');
console.log(`Decoded URL to proxy: ${urlToProxy}`);
req.url = urlToProxy;
const handler = uvPath.requireHandle();
if (typeof handler === 'function') {
handler(req, res);
} else {
console.error('Invalid handler function');
res.status(500).send('Internal server error');
}
} catch (error) {
console.error('Error decoding URL:', error);
res.status(400).send('Invalid URL encoding');
}
});

httpServer.listen(port, () => {
Expand Down
8 changes: 6 additions & 2 deletions uv.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
self.__uv$config = {
prefix: '/service/',
bare: '/bare/',
encodeUrl: Ultraviolet.codec.xor.encode,
decodeUrl: Ultraviolet.codec.xor.decode,
encodeUrl: function(url) {
return btoa(url);
},
decodeUrl: function(encodedUrl) {
return atob(encodedUrl);
},
handler: '/dist/uv.handler.js',
bundle: '/dist/uv.bundle.js',
config: '/dist/uv.config.js',
Expand Down