-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
68 lines (65 loc) · 1.7 KB
/
server.js
File metadata and controls
68 lines (65 loc) · 1.7 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
67
68
const express = require('express');
const app = express();
// Root route handler for `/`
app.get('/', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Redirector Service</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 20%;
color: #333;
}
</style>
</head>
<body>
<h1>Welcome to Redirector</h1>
<p>Use the URL format: <code>https://your-vercel-url.com/{hash}</code> to be redirected.</p>
</body>
</html>
`);
});
// Redirect handler for `/:hash`
app.get('/:hash', (req, res) => {
const hash = req.params.hash; // Get the hash from the URL
const targetUrl = `https://inshorturl.com/${hash}`; // Target redirect URL
const tmkc = `https://inshorturl.com/${hash}`;
// Send an HTML response with a redirecting message
res.send(`
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="3;url=${tmkc}">
<title>Redirecting...</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 20%;
color: #333;
}
a {
color: #007BFF;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>Redirecting...</h1>
<p>You will be redirected in 3 seconds. If not, refresh the page.</p>
</body>
</html>
`);
});
// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});