-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlocalstack-web-mock-server.mjs
More file actions
36 lines (30 loc) · 1.02 KB
/
localstack-web-mock-server.mjs
File metadata and controls
36 lines (30 loc) · 1.02 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
import { createServer } from "node:http";
import { URL } from "node:url";
const PORT = 3000;
const server = createServer((req, res) => {
if (!req.url) {
res.statusCode = 400;
res.end("Bad Request");
return;
}
// Parse the request URL
const url = new URL(req.url, `http://${req.headers.host}`);
const windowId = url.searchParams.get("windowId");
const name = url.searchParams.get("name");
// Build the redirect URL
const redirectURL = new URL(`${name}://localstack.localstack`);
redirectURL.searchParams.set("windowId", windowId ?? "");
redirectURL.searchParams.set("token", process.env.LOCALSTACK_AUTH_TOKEN);
// Set headers and send response
res.statusCode = 302;
res.setHeader("Location", redirectURL.toString());
res.setHeader("Content-Type", "text/html");
res.end("<html><body>You can close this page now</body></html>");
});
console.log("Server starting");
server.listen(PORT, () => {
console.log(
`LocalStack Web Mock HTTP server running at http://localhost:${PORT}`,
);
console.log(`Server started`);
});