-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxyServer.js
More file actions
66 lines (60 loc) · 1.95 KB
/
proxyServer.js
File metadata and controls
66 lines (60 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const express = require('express');
let currentRedirectUrl = null;
const app = express();
// API to update redirect URL
app.post('/setRedirect', express.json(), (req, res) => {
const { url } = req.body;
if (!url) return res.status(400).send('Missing URL');
currentRedirectUrl = url;
console.log(`🔁 Updated redirect URL to: ${url}`);
res.sendStatus(200);
});
app.get('/', (req, res) => {
if (!currentRedirectUrl) {
return res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Waiting</title>
<style>
body {
font-family: sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
color: #555;
}
</style>
<script>
async function checkRedirect() {
try {
const res = await fetch('/redirect-check');
const data = await res.json();
if (data && data.url) {
window.location.href = data.url;
}
} catch (e) {
console.error('Polling failed', e);
}
}
setInterval(checkRedirect, 2000); // Check every 2 seconds
</script>
</head>
<body>
<h1>⏳ Preparing the spreadsheet...</h1>
</body>
</html>
`);
}
res.redirect(302, currentRedirectUrl);
});
app.get('/redirect-check', (req, res) => {
res.json({ url: currentRedirectUrl || null });
});
const PORT = 3000;
app.listen(PORT, () => {
console.log(`🚀 Proxy running on http://localhost:${PORT}`);
});