-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-server.js
More file actions
48 lines (41 loc) · 1.43 KB
/
test-server.js
File metadata and controls
48 lines (41 loc) · 1.43 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
const http = require("node:http");
const server = http.createServer((req, res) => {
// CORS + Private Network Access headers
// Required for HTTPS pages to reach localhost
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "*");
res.setHeader("Access-Control-Allow-Private-Network", "true");
// Handle CORS preflight (including Private Network Access preflight)
if (req.method === "OPTIONS") {
res.writeHead(204);
res.end();
return;
}
// Collect request body
let body = "";
req.on("data", (chunk) => {
body += chunk;
});
req.on("end", () => {
console.log(`\n📨 ${req.method} ${req.url}`);
console.log(` Headers: ${JSON.stringify(req.headers, null, 2).split("\n").join("\n ")}`);
if (body) console.log(` Body: ${body}`);
// Respond
const response = {
received: true,
method: req.method,
path: req.url,
timestamp: new Date().toISOString(),
echo: body ? JSON.parse(body) : null,
};
console.log(" ✅ Responding 200 OK");
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify(response, null, 2));
});
});
server.listen(5000, () => {
console.log("🚀 Test server running on http://localhost:5000");
console.log(" CORS + Private Network Access headers enabled");
console.log(" Waiting for webhooks from BridgeHook...\n");
});