-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture-url.js
More file actions
39 lines (37 loc) · 1.11 KB
/
capture-url.js
File metadata and controls
39 lines (37 loc) · 1.11 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
global.__dirname = new URL('./', import.meta.url).href
.replace('file://', '')
.replace('file:', '');
import fs from 'fs';
import express from 'express';
async function main() {
const app = express();
app.all('*', async (req, res) => {
if (req.query.length > 100) {
res.status(302);
res.setHeader('location', '/');
res.end();
} else if (req.query.origin) {
const absoluteUrl = new URL(req.query.origin);
fs.writeFileSync(
__dirname + '/.wprc.json',
JSON.stringify({ absoluteUrl })
);
res.status(302);
res.setHeader('location', '/');
res.end();
console.log(`Got it! It's ${absoluteUrl}. Starting the dev workflow now`);
process.exit(0);
} else {
res.setHeader('content-type', 'text/html');
res.send(
`<!DOCTYPE html><html><head><script>window.location.href = '/?origin=' + encodeURIComponent(window.location.origin);<\/script></head></html>`
);
res.end();
}
});
const port = 3000;
app.listen(port, async () => {
console.log(`Capturing the current container URL...`);
});
}
main();